<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-comment">{-
(c) The GRASP/AQUA Project, Glasgow University, 1993-1998


                        -----------------
                        A demand analysis
                        -----------------
-}</span><span>
</span><span id="line-9"></span><span>
</span><span id="line-10"></span><span class="hs-pragma">{-# LANGUAGE CPP #-}</span><span>
</span><span id="line-11"></span><span>
</span><span id="line-12"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Core.Opt.DmdAnal</span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalProgram"><span class="hs-identifier">dmdAnalProgram</span></a></span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span class="hs-cpp">

#include &quot;HsVersions.h&quot;
</span><span>
</span><span id="line-16"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Prelude.html"><span class="hs-identifier">GHC.Prelude</span></a></span><span>
</span><span id="line-17"></span><span>
</span><span id="line-18"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html"><span class="hs-identifier">GHC.Driver.Session</span></a></span><span>
</span><span id="line-19"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.Utils.html"><span class="hs-identifier">GHC.Core.Opt.WorkWrap.Utils</span></a></span><span>
</span><span id="line-20"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html"><span class="hs-identifier">GHC.Types.Demand</span></a></span><span>   </span><span class="hs-comment">-- All of it</span><span>
</span><span id="line-21"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.html"><span class="hs-identifier">GHC.Core</span></a></span><span>
</span><span id="line-22"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Multiplicity.html"><span class="hs-identifier">GHC.Core.Multiplicity</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#scaledThing"><span class="hs-identifier">scaledThing</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-23"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Seq.html"><span class="hs-identifier">GHC.Core.Seq</span></a></span><span>     </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.Seq.html#seqBinds"><span class="hs-identifier">seqBinds</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html"><span class="hs-identifier">GHC.Utils.Outputable</span></a></span><span>
</span><span id="line-25"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.Env.html"><span class="hs-identifier">GHC.Types.Var.Env</span></a></span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.Set.html"><span class="hs-identifier">GHC.Types.Var.Set</span></a></span><span>
</span><span id="line-27"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html"><span class="hs-identifier">GHC.Types.Basic</span></a></span><span>
</span><span id="line-28"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.List.html#"><span class="hs-identifier">Data.List</span></a></span><span>        </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../base/src/Data.Traversable.html#mapAccumL"><span class="hs-identifier">mapAccumL</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-29"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.DataCon.html"><span class="hs-identifier">GHC.Core.DataCon</span></a></span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.ForeignCall.html"><span class="hs-identifier">GHC.Types.ForeignCall</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Types.ForeignCall.html#isSafeForeignCall"><span class="hs-identifier">isSafeForeignCall</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-31"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Id.html"><span class="hs-identifier">GHC.Types.Id</span></a></span><span>
</span><span id="line-32"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Id.Info.html"><span class="hs-identifier">GHC.Types.Id.Info</span></a></span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Utils.html"><span class="hs-identifier">GHC.Core.Utils</span></a></span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html"><span class="hs-identifier">GHC.Core.TyCon</span></a></span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Type.html"><span class="hs-identifier">GHC.Core.Type</span></a></span><span>
</span><span id="line-36"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.FVs.html"><span class="hs-identifier">GHC.Core.FVs</span></a></span><span>      </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.FVs.html#exprFreeIds"><span class="hs-identifier">exprFreeIds</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.FVs.html#ruleRhsFreeIds"><span class="hs-identifier">ruleRhsFreeIds</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-37"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Coercion.html"><span class="hs-identifier">GHC.Core.Coercion</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier">Coercion</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.FVs.html#coVarsOfCo"><span class="hs-identifier">coVarsOfCo</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-38"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html"><span class="hs-identifier">GHC.Core.FamInstEnv</span></a></span><span>
</span><span id="line-39"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Misc.html"><span class="hs-identifier">GHC.Utils.Misc</span></a></span><span>
</span><span id="line-40"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Data.Maybe.html"><span class="hs-identifier">GHC.Data.Maybe</span></a></span><span>         </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../base/src/Data.Maybe.html#isJust"><span class="hs-identifier">isJust</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-41"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Builtin.PrimOps.html"><span class="hs-identifier">GHC.Builtin.PrimOps</span></a></span><span>
</span><span id="line-42"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Builtin.Types.Prim.html"><span class="hs-identifier">GHC.Builtin.Types.Prim</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Builtin.Types.Prim.html#realWorldStatePrimTy"><span class="hs-identifier">realWorldStatePrimTy</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-43"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html"><span class="hs-identifier">GHC.Utils.Error</span></a></span><span>        </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#dumpIfSet_dyn"><span class="hs-identifier">dumpIfSet_dyn</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#DumpFormat"><span class="hs-identifier">DumpFormat</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-44"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Unique.Set.html"><span class="hs-identifier">GHC.Types.Unique.Set</span></a></span><span>
</span><span id="line-45"></span><span>
</span><span id="line-46"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
\subsection{Top level stuff}
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-53"></span><span>
</span><span id="line-54"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalProgram"><span class="hs-identifier hs-type">dmdAnalProgram</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier hs-type">FamInstEnvs</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreProgram"><span class="hs-identifier hs-type">CoreProgram</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="GHC.Core.html#CoreProgram"><span class="hs-identifier hs-type">CoreProgram</span></a></span><span>
</span><span id="line-55"></span><span id="dmdAnalProgram"><span class="annot"><span class="annottext">dmdAnalProgram :: DynFlags -&gt; FamInstEnvs -&gt; CoreProgram -&gt; IO CoreProgram
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalProgram"><span class="hs-identifier hs-var hs-var">dmdAnalProgram</span></a></span></span><span> </span><span id="local-6989586621680960779"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680960779"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680960778"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680960778"><span class="hs-identifier hs-var">fam_envs</span></a></span></span><span> </span><span id="local-6989586621680960777"><span class="annot"><span class="annottext">CoreProgram
</span><a href="#local-6989586621680960777"><span class="hs-identifier hs-var">binds</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-56"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680960776"><span class="annot"><span class="annottext">env :: AnalEnv
</span><a href="#local-6989586621680960776"><span class="hs-identifier hs-var hs-var">env</span></a></span></span><span>             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags -&gt; FamInstEnvs -&gt; AnalEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#emptyAnalEnv"><span class="hs-identifier hs-var">emptyAnalEnv</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680960779"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680960778"><span class="hs-identifier hs-var">fam_envs</span></a></span><span>
</span><span id="line-57"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680960772"><span class="annot"><span class="annottext">binds_plus_dmds :: CoreProgram
</span><a href="#local-6989586621680960772"><span class="hs-identifier hs-var hs-var">binds_plus_dmds</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(AnalEnv, CoreProgram) -&gt; CoreProgram
forall a b. (a, b) -&gt; b
</span><a href="../../base/src/Data.Tuple.html#snd"><span class="hs-identifier hs-var">snd</span></a></span><span> </span><span class="annot"><span class="annottext">((AnalEnv, CoreProgram) -&gt; CoreProgram)
-&gt; (AnalEnv, CoreProgram) -&gt; CoreProgram
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">(AnalEnv -&gt; CoreBind -&gt; (AnalEnv, CoreBind))
-&gt; AnalEnv -&gt; CoreProgram -&gt; (AnalEnv, CoreProgram)
forall (t :: * -&gt; *) s a b.
Traversable t =&gt;
(s -&gt; a -&gt; (s, b)) -&gt; s -&gt; t a -&gt; (s, t b)
</span><a href="../../base/src/Data.Traversable.html#mapAccumL"><span class="hs-identifier hs-var">mapAccumL</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; CoreBind -&gt; (AnalEnv, CoreBind)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalTopBind"><span class="hs-identifier hs-var">dmdAnalTopBind</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960776"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CoreProgram
</span><a href="#local-6989586621680960777"><span class="hs-identifier hs-var">binds</span></a></span><span>
</span><span id="line-58"></span><span>  </span><span class="annot"><span class="annottext">DynFlags -&gt; DumpFlag -&gt; String -&gt; DumpFormat -&gt; SDoc -&gt; IO ()
</span><a href="GHC.Utils.Error.html#dumpIfSet_dyn"><span class="hs-identifier hs-var">dumpIfSet_dyn</span></a></span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680960779"><span class="hs-identifier hs-var">dflags</span></a></span><span> </span><span class="annot"><span class="annottext">DumpFlag
</span><a href="GHC.Driver.Flags.html#Opt_D_dump_str_signatures"><span class="hs-identifier hs-var">Opt_D_dump_str_signatures</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;Strictness signatures&quot;</span></span><span> </span><span class="annot"><span class="annottext">DumpFormat
</span><a href="GHC.Utils.Error.html#FormatText"><span class="hs-identifier hs-var">FormatText</span></a></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; IO ()) -&gt; SDoc -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-59"></span><span>    </span><span class="annot"><span class="annottext">(IdInfo -&gt; SDoc) -&gt; CoreProgram -&gt; SDoc
</span><a href="GHC.Core.Utils.html#dumpIdInfoOfProgram"><span class="hs-identifier hs-var">dumpIdInfoOfProgram</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">StrictSig -&gt; SDoc
</span><a href="GHC.Types.Demand.html#pprIfaceStrictSig"><span class="hs-identifier hs-var">pprIfaceStrictSig</span></a></span><span> </span><span class="annot"><span class="annottext">(StrictSig -&gt; SDoc) -&gt; (IdInfo -&gt; StrictSig) -&gt; IdInfo -&gt; SDoc
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">IdInfo -&gt; StrictSig
</span><a href="GHC.Types.Id.Info.html#strictnessInfo"><span class="hs-identifier hs-var hs-var">strictnessInfo</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CoreProgram
</span><a href="#local-6989586621680960772"><span class="hs-identifier hs-var">binds_plus_dmds</span></a></span><span>
</span><span id="line-60"></span><span>  </span><span class="hs-comment">-- See Note [Stamp out space leaks in demand analysis]</span><span>
</span><span id="line-61"></span><span>  </span><span class="annot"><span class="annottext">CoreProgram -&gt; ()
</span><a href="GHC.Core.Seq.html#seqBinds"><span class="hs-identifier hs-var">seqBinds</span></a></span><span> </span><span class="annot"><span class="annottext">CoreProgram
</span><a href="#local-6989586621680960772"><span class="hs-identifier hs-var">binds_plus_dmds</span></a></span><span> </span><span class="annot"><span class="annottext">() -&gt; IO CoreProgram -&gt; IO CoreProgram
</span><span class="hs-operator hs-var">`seq`</span></span><span> </span><span class="annot"><span class="annottext">CoreProgram -&gt; IO CoreProgram
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">CoreProgram
</span><a href="#local-6989586621680960772"><span class="hs-identifier hs-var">binds_plus_dmds</span></a></span><span>
</span><span id="line-62"></span><span>
</span><span id="line-63"></span><span class="hs-comment">-- Analyse a (group of) top-level binding(s)</span><span>
</span><span id="line-64"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalTopBind"><span class="hs-identifier hs-type">dmdAnalTopBind</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span>
</span><span id="line-65"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreBind"><span class="hs-identifier hs-type">CoreBind</span></a></span><span>
</span><span id="line-66"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreBind"><span class="hs-identifier hs-type">CoreBind</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-67"></span><span id="dmdAnalTopBind"><span class="annot"><span class="annottext">dmdAnalTopBind :: AnalEnv -&gt; CoreBind -&gt; (AnalEnv, CoreBind)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalTopBind"><span class="hs-identifier hs-var hs-var">dmdAnalTopBind</span></a></span></span><span> </span><span id="local-6989586621680960764"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960764"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#NonRec"><span class="hs-identifier hs-type">NonRec</span></a></span><span> </span><span id="local-6989586621680960762"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960762"><span class="hs-identifier hs-var">id</span></a></span></span><span> </span><span id="local-6989586621680960761"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960761"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-68"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="annottext">TopLevelFlag -&gt; AnalEnv -&gt; Var -&gt; StrictSig -&gt; AnalEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#extendAnalEnv"><span class="hs-identifier hs-var">extendAnalEnv</span></a></span><span> </span><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="GHC.Types.Basic.html#TopLevel"><span class="hs-identifier hs-var">TopLevel</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960764"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960762"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">StrictSig
</span><a href="#local-6989586621680960758"><span class="hs-identifier hs-var">sig</span></a></span><span>
</span><span id="line-69"></span><span>    </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Var -&gt; CoreExpr -&gt; CoreBind
forall b. b -&gt; Expr b -&gt; Bind b
</span><a href="GHC.Core.html#NonRec"><span class="hs-identifier hs-var">NonRec</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; StrictSig -&gt; Var
</span><a href="GHC.Types.Id.html#setIdStrictness"><span class="hs-identifier hs-var">setIdStrictness</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960762"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">StrictSig
</span><a href="#local-6989586621680960758"><span class="hs-identifier hs-var">sig</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960756"><span class="hs-identifier hs-var">rhs'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-70"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-71"></span><span>    </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960758"><span class="annot"><span class="annottext">StrictSig
</span><a href="#local-6989586621680960758"><span class="hs-identifier hs-var">sig</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960756"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960756"><span class="hs-identifier hs-var">rhs'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe [Var]
-&gt; AnalEnv
-&gt; CleanDemand
-&gt; Var
-&gt; CoreExpr
-&gt; (DmdEnv, StrictSig, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalRhsLetDown"><span class="hs-identifier hs-var">dmdAnalRhsLetDown</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe [Var]
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960764"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="GHC.Types.Demand.html#cleanEvalDmd"><span class="hs-identifier hs-var">cleanEvalDmd</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960762"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960761"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-72"></span><span>
</span><span id="line-73"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalTopBind"><span class="hs-identifier hs-var">dmdAnalTopBind</span></a></span><span> </span><span id="local-6989586621680960753"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960753"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Rec"><span class="hs-identifier hs-type">Rec</span></a></span><span> </span><span id="local-6989586621680960751"><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960751"><span class="hs-identifier hs-var">pairs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-74"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960750"><span class="hs-identifier hs-var">env'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)] -&gt; CoreBind
forall b. [(b, Expr b)] -&gt; Bind b
</span><a href="GHC.Core.html#Rec"><span class="hs-identifier hs-var">Rec</span></a></span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960749"><span class="hs-identifier hs-var">pairs'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-75"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-76"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680960750"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960750"><span class="hs-identifier hs-var">env'</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960749"><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960749"><span class="hs-identifier hs-var">pairs'</span></a></span></span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TopLevelFlag
-&gt; AnalEnv
-&gt; CleanDemand
-&gt; [(Var, CoreExpr)]
-&gt; (AnalEnv, DmdEnv, [(Var, CoreExpr)])
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdFix"><span class="hs-identifier hs-var">dmdFix</span></a></span><span> </span><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="GHC.Types.Basic.html#TopLevel"><span class="hs-identifier hs-var">TopLevel</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960753"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="GHC.Types.Demand.html#cleanEvalDmd"><span class="hs-identifier hs-var">cleanEvalDmd</span></a></span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960751"><span class="hs-identifier hs-var">pairs</span></a></span><span>
</span><span id="line-77"></span><span>                </span><span class="hs-comment">-- We get two iterations automatically</span><span>
</span><span id="line-78"></span><span>                </span><span class="hs-comment">-- c.f. the NonRec case above</span><span>
</span><span id="line-79"></span><span>
</span><span id="line-80"></span><span class="hs-comment">{- Note [Stamp out space leaks in demand analysis]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The demand analysis pass outputs a new copy of the Core program in
which binders have been annotated with demand and strictness
information. It's tiresome to ensure that this information is fully
evaluated everywhere that we produce it, so we just run a single
seqBinds over the output before returning it, to ensure that there are
no references holding on to the input Core program.

This makes a ~30% reduction in peak memory usage when compiling
DynFlags (cf #9675 and #13426).

This is particularly important when we are doing late demand analysis,
since we don't do a seqBinds at any point thereafter. Hence code
generation would hold on to an extra copy of the Core program, via
unforced thunks in demand or strictness information; and it is the
most memory-intensive part of the compilation process, so this added
seqBinds makes a big difference in peak memory usage.
-}</span><span>
</span><span id="line-99"></span><span>
</span><span id="line-100"></span><span>
</span><span id="line-101"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
\subsection{The analyser itself}
*                                                                      *
************************************************************************

Note [Ensure demand is strict]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It's important not to analyse e with a lazy demand because
a) When we encounter   case s of (a,b) -&gt;
        we demand s with U(d1d2)... but if the overall demand is lazy
        that is wrong, and we'd need to reduce the demand on s,
        which is inconvenient
b) More important, consider
        f (let x = R in x+x), where f is lazy
   We still want to mark x as demanded, because it will be when we
   enter the let.  If we analyse f's arg with a Lazy demand, we'll
   just mark x as Lazy
c) The application rule wouldn't be right either
   Evaluating (f x) in a L demand does *not* cause
   evaluation of f in a C(L) demand!
-}</span><span>
</span><span id="line-124"></span><span>
</span><span id="line-125"></span><span class="hs-comment">-- If e is complicated enough to become a thunk, its contents will be evaluated</span><span>
</span><span id="line-126"></span><span class="hs-comment">-- at most once, so oneify it.</span><span>
</span><span id="line-127"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdTransformThunkDmd"><span class="hs-identifier hs-type">dmdTransformThunkDmd</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#Demand"><span class="hs-identifier hs-type">Demand</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#Demand"><span class="hs-identifier hs-type">Demand</span></a></span><span>
</span><span id="line-128"></span><span id="dmdTransformThunkDmd"><span class="annot"><span class="annottext">dmdTransformThunkDmd :: CoreExpr -&gt; Demand -&gt; Demand
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdTransformThunkDmd"><span class="hs-identifier hs-var hs-var">dmdTransformThunkDmd</span></a></span></span><span> </span><span id="local-6989586621680960746"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960746"><span class="hs-identifier hs-var">e</span></a></span></span><span>
</span><span id="line-129"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; Bool
</span><a href="GHC.Core.Utils.html#exprIsTrivial"><span class="hs-identifier hs-var">exprIsTrivial</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960746"><span class="hs-identifier hs-var">e</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Demand -&gt; Demand
forall a. a -&gt; a
</span><a href="../../base/src/GHC.Base.html#id"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-130"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Demand -&gt; Demand
forall s u. JointDmd s (Use u) -&gt; JointDmd s (Use u)
</span><a href="GHC.Types.Demand.html#oneifyDmd"><span class="hs-identifier hs-var">oneifyDmd</span></a></span><span>
</span><span id="line-131"></span><span>
</span><span id="line-132"></span><span class="hs-comment">-- Do not process absent demands</span><span>
</span><span id="line-133"></span><span class="hs-comment">-- Otherwise act like in a normal demand analysis</span><span>
</span><span id="line-134"></span><span class="hs-comment">-- See &#8614;* relation in the Cardinality Analysis paper</span><span>
</span><span id="line-135"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalStar"><span class="hs-identifier hs-type">dmdAnalStar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span>
</span><span id="line-136"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#Demand"><span class="hs-identifier hs-type">Demand</span></a></span><span>   </span><span class="hs-comment">-- This one takes a *Demand*</span><span>
</span><span id="line-137"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-comment">-- Should obey the let/app invariant</span><span>
</span><span id="line-138"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Demand.html#BothDmdArg"><span class="hs-identifier hs-type">BothDmdArg</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-139"></span><span id="dmdAnalStar"><span class="annot"><span class="annottext">dmdAnalStar :: AnalEnv -&gt; Demand -&gt; CoreExpr -&gt; (BothDmdArg, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalStar"><span class="hs-identifier hs-var hs-var">dmdAnalStar</span></a></span></span><span> </span><span id="local-6989586621680960741"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960741"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960740"><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960740"><span class="hs-identifier hs-var">dmd</span></a></span></span><span> </span><span id="local-6989586621680960739"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960739"><span class="hs-identifier hs-var">e</span></a></span></span><span>
</span><span id="line-140"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680960738"><span class="annot"><span class="annottext">DmdShell
</span><a href="#local-6989586621680960738"><span class="hs-identifier hs-var">dmd_shell</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960737"><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960737"><span class="hs-identifier hs-var">cd</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Demand -&gt; (DmdShell, CleanDemand)
</span><a href="GHC.Types.Demand.html#toCleanDmd"><span class="hs-identifier hs-var">toCleanDmd</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960740"><span class="hs-identifier hs-var">dmd</span></a></span><span>
</span><span id="line-141"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680960735"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960735"><span class="hs-identifier hs-var">dmd_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960734"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960734"><span class="hs-identifier hs-var">e'</span></a></span></span><span class="hs-special">)</span><span>    </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal"><span class="hs-identifier hs-var">dmdAnal</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960741"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960737"><span class="hs-identifier hs-var">cd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960739"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-142"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT2</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">not</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">isUnliftedType</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">exprType</span><span> </span><span class="hs-identifier">e</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-operator">||</span><span> </span><span class="hs-identifier">exprOkForSpeculation</span><span> </span><span class="hs-identifier">e</span><span class="hs-special">,</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">e</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-143"></span><span>    </span><span class="hs-comment">-- The argument 'e' should satisfy the let/app invariant</span><span>
</span><span id="line-144"></span><span>    </span><span class="hs-comment">-- See Note [Analysing with absent demand] in GHC.Types.Demand</span><span>
</span><span id="line-145"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdShell -&gt; DmdType -&gt; BothDmdArg
</span><a href="GHC.Types.Demand.html#postProcessDmdType"><span class="hs-identifier hs-var">postProcessDmdType</span></a></span><span> </span><span class="annot"><span class="annottext">DmdShell
</span><a href="#local-6989586621680960738"><span class="hs-identifier hs-var">dmd_shell</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960735"><span class="hs-identifier hs-var">dmd_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960734"><span class="hs-identifier hs-var">e'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-146"></span><span>
</span><span id="line-147"></span><span class="hs-comment">-- Main Demand Analsysis machinery</span><span>
</span><span id="line-148"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal"><span class="hs-identifier hs-type">dmdAnal</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal%27"><span class="hs-identifier hs-type">dmdAnal'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span>
</span><span id="line-149"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#CleanDemand"><span class="hs-identifier hs-type">CleanDemand</span></a></span><span>         </span><span class="hs-comment">-- The main one takes a *CleanDemand*</span><span>
</span><span id="line-150"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-151"></span><span>
</span><span id="line-152"></span><span class="hs-comment">-- The CleanDemand is always strict and not absent</span><span>
</span><span id="line-153"></span><span class="hs-comment">--    See Note [Ensure demand is strict]</span><span>
</span><span id="line-154"></span><span>
</span><span id="line-155"></span><span id="dmdAnal"><span class="annot"><span class="annottext">dmdAnal :: AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal"><span class="hs-identifier hs-var hs-var">dmdAnal</span></a></span></span><span> </span><span id="local-6989586621680960721"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960721"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960720"><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960720"><span class="hs-identifier hs-var">d</span></a></span></span><span> </span><span id="local-6989586621680960719"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960719"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-comment">-- pprTrace &quot;dmdAnal&quot; (ppr d &lt;+&gt; ppr e) $</span><span>
</span><span id="line-156"></span><span>                  </span><span class="annot"><span class="annottext">AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal%27"><span class="hs-identifier hs-var">dmdAnal'</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960721"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960720"><span class="hs-identifier hs-var">d</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960719"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-157"></span><span>
</span><span id="line-158"></span><span id="dmdAnal%27"><span class="annot"><span class="annottext">dmdAnal' :: AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal%27"><span class="hs-identifier hs-var hs-var">dmdAnal'</span></a></span></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lit"><span class="hs-identifier hs-type">Lit</span></a></span><span> </span><span id="local-6989586621680960717"><span class="annot"><span class="annottext">Literal
</span><a href="#local-6989586621680960717"><span class="hs-identifier hs-var">lit</span></a></span></span><span class="hs-special">)</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="GHC.Types.Demand.html#nopDmdType"><span class="hs-identifier hs-var">nopDmdType</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Literal -&gt; CoreExpr
forall b. Literal -&gt; Expr b
</span><a href="GHC.Core.html#Lit"><span class="hs-identifier hs-var">Lit</span></a></span><span> </span><span class="annot"><span class="annottext">Literal
</span><a href="#local-6989586621680960717"><span class="hs-identifier hs-var">lit</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-159"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal%27"><span class="hs-identifier hs-var">dmdAnal'</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span id="local-6989586621680960714"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680960714"><span class="hs-identifier hs-var">ty</span></a></span></span><span class="hs-special">)</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="GHC.Types.Demand.html#nopDmdType"><span class="hs-identifier hs-var">nopDmdType</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Type -&gt; CoreExpr
forall b. Type -&gt; Expr b
</span><a href="GHC.Core.html#Type"><span class="hs-identifier hs-var">Type</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680960714"><span class="hs-identifier hs-var">ty</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- Doesn't happen, in fact</span><span>
</span><span id="line-160"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal%27"><span class="hs-identifier hs-var">dmdAnal'</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span> </span><span id="local-6989586621680960712"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680960712"><span class="hs-identifier hs-var">co</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-161"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdEnv -&gt; DmdType
</span><a href="GHC.Core.Opt.DmdAnal.html#unitDmdType"><span class="hs-identifier hs-var">unitDmdType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Coercion -&gt; DmdEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#coercionDmdEnv"><span class="hs-identifier hs-var">coercionDmdEnv</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680960712"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Coercion -&gt; CoreExpr
forall b. Coercion -&gt; Expr b
</span><a href="GHC.Core.html#Coercion"><span class="hs-identifier hs-var">Coercion</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680960712"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-162"></span><span>
</span><span id="line-163"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal%27"><span class="hs-identifier hs-var">dmdAnal'</span></a></span><span> </span><span id="local-6989586621680960709"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960709"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960708"><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960708"><span class="hs-identifier hs-var">dmd</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680960706"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960706"><span class="hs-identifier hs-var">var</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-164"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">AnalEnv -&gt; Var -&gt; CleanDemand -&gt; DmdType
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdTransform"><span class="hs-identifier hs-var">dmdTransform</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960709"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960706"><span class="hs-identifier hs-var">var</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960708"><span class="hs-identifier hs-var">dmd</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Var -&gt; CoreExpr
forall b. Var -&gt; Expr b
</span><a href="GHC.Core.html#Var"><span class="hs-identifier hs-var">Var</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960706"><span class="hs-identifier hs-var">var</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-165"></span><span>
</span><span id="line-166"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal%27"><span class="hs-identifier hs-var">dmdAnal'</span></a></span><span> </span><span id="local-6989586621680960704"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960704"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960703"><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960703"><span class="hs-identifier hs-var">dmd</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Cast"><span class="hs-identifier hs-type">Cast</span></a></span><span> </span><span id="local-6989586621680960701"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960701"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span id="local-6989586621680960700"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680960700"><span class="hs-identifier hs-var">co</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-167"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960699"><span class="hs-identifier hs-var">dmd_ty</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; BothDmdArg -&gt; DmdType
</span><a href="GHC.Types.Demand.html#bothDmdType"><span class="hs-operator hs-var">`bothDmdType`</span></a></span><span> </span><span class="annot"><span class="annottext">DmdEnv -&gt; BothDmdArg
</span><a href="GHC.Types.Demand.html#mkBothDmdArg"><span class="hs-identifier hs-var">mkBothDmdArg</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Coercion -&gt; DmdEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#coercionDmdEnv"><span class="hs-identifier hs-var">coercionDmdEnv</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680960700"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; Coercion -&gt; CoreExpr
forall b. Expr b -&gt; Coercion -&gt; Expr b
</span><a href="GHC.Core.html#Cast"><span class="hs-identifier hs-var">Cast</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960696"><span class="hs-identifier hs-var">e'</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680960700"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-168"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-169"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680960699"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960699"><span class="hs-identifier hs-var">dmd_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960696"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960696"><span class="hs-identifier hs-var">e'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal"><span class="hs-identifier hs-var">dmdAnal</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960704"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960703"><span class="hs-identifier hs-var">dmd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960701"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-170"></span><span>
</span><span id="line-171"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal%27"><span class="hs-identifier hs-var">dmdAnal'</span></a></span><span> </span><span id="local-6989586621680960695"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960695"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960694"><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960694"><span class="hs-identifier hs-var">dmd</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-type">Tick</span></a></span><span> </span><span id="local-6989586621680960692"><span class="annot"><span class="annottext">Tickish Var
</span><a href="#local-6989586621680960692"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span id="local-6989586621680960691"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960691"><span class="hs-identifier hs-var">e</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-172"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960690"><span class="hs-identifier hs-var">dmd_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Tickish Var -&gt; CoreExpr -&gt; CoreExpr
forall b. Tickish Var -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#Tick"><span class="hs-identifier hs-var">Tick</span></a></span><span> </span><span class="annot"><span class="annottext">Tickish Var
</span><a href="#local-6989586621680960692"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960689"><span class="hs-identifier hs-var">e'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-173"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-174"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680960690"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960690"><span class="hs-identifier hs-var">dmd_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960689"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960689"><span class="hs-identifier hs-var">e'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal"><span class="hs-identifier hs-var">dmdAnal</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960695"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960694"><span class="hs-identifier hs-var">dmd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960691"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-175"></span><span>
</span><span id="line-176"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal%27"><span class="hs-identifier hs-var">dmdAnal'</span></a></span><span> </span><span id="local-6989586621680960688"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960688"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960687"><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960687"><span class="hs-identifier hs-var">dmd</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#App"><span class="hs-identifier hs-type">App</span></a></span><span> </span><span id="local-6989586621680960685"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960685"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span id="local-6989586621680960684"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680960684"><span class="hs-identifier hs-var">ty</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-177"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960683"><span class="hs-identifier hs-var">fun_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; CoreExpr -&gt; CoreExpr
forall b. Expr b -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#App"><span class="hs-identifier hs-var">App</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960682"><span class="hs-identifier hs-var">fun'</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Type -&gt; CoreExpr
forall b. Type -&gt; Expr b
</span><a href="GHC.Core.html#Type"><span class="hs-identifier hs-var">Type</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680960684"><span class="hs-identifier hs-var">ty</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-178"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-179"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680960683"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960683"><span class="hs-identifier hs-var">fun_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960682"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960682"><span class="hs-identifier hs-var">fun'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal"><span class="hs-identifier hs-var">dmdAnal</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960688"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960687"><span class="hs-identifier hs-var">dmd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960685"><span class="hs-identifier hs-var">fun</span></a></span><span>
</span><span id="line-180"></span><span>
</span><span id="line-181"></span><span class="hs-comment">-- Lots of the other code is there to make this</span><span>
</span><span id="line-182"></span><span class="hs-comment">-- beautiful, compositional, application rule :-)</span><span>
</span><span id="line-183"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal%27"><span class="hs-identifier hs-var">dmdAnal'</span></a></span><span> </span><span id="local-6989586621680960681"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960681"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960680"><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960680"><span class="hs-identifier hs-var">dmd</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#App"><span class="hs-identifier hs-type">App</span></a></span><span> </span><span id="local-6989586621680960679"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960679"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621680960678"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960678"><span class="hs-identifier hs-var">arg</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-184"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-comment">-- This case handles value arguments (type args handled above)</span><span>
</span><span id="line-185"></span><span>    </span><span class="hs-comment">-- Crucially, coercions /are/ handled here, because they are</span><span>
</span><span id="line-186"></span><span>    </span><span class="hs-comment">-- value arguments (#10288)</span><span>
</span><span id="line-187"></span><span>    </span><span class="hs-keyword">let</span><span>
</span><span id="line-188"></span><span>        </span><span id="local-6989586621680960677"><span class="annot"><span class="annottext">call_dmd :: CleanDemand
</span><a href="#local-6989586621680960677"><span class="hs-identifier hs-var hs-var">call_dmd</span></a></span></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CleanDemand -&gt; CleanDemand
</span><a href="GHC.Types.Demand.html#mkCallDmd"><span class="hs-identifier hs-var">mkCallDmd</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960680"><span class="hs-identifier hs-var">dmd</span></a></span><span>
</span><span id="line-189"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680960675"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960675"><span class="hs-identifier hs-var">fun_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960674"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960674"><span class="hs-identifier hs-var">fun'</span></a></span></span><span class="hs-special">)</span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal"><span class="hs-identifier hs-var">dmdAnal</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960681"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960677"><span class="hs-identifier hs-var">call_dmd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960679"><span class="hs-identifier hs-var">fun</span></a></span><span>
</span><span id="line-190"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680960673"><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960673"><span class="hs-identifier hs-var">arg_dmd</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960672"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960672"><span class="hs-identifier hs-var">res_ty</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; (Demand, DmdType)
</span><a href="GHC.Types.Demand.html#splitDmdTy"><span class="hs-identifier hs-var">splitDmdTy</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960675"><span class="hs-identifier hs-var">fun_ty</span></a></span><span>
</span><span id="line-191"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680960670"><span class="annot"><span class="annottext">BothDmdArg
</span><a href="#local-6989586621680960670"><span class="hs-identifier hs-var">arg_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960669"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960669"><span class="hs-identifier hs-var">arg'</span></a></span></span><span class="hs-special">)</span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; Demand -&gt; CoreExpr -&gt; (BothDmdArg, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalStar"><span class="hs-identifier hs-var">dmdAnalStar</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960681"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreExpr -&gt; Demand -&gt; Demand
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdTransformThunkDmd"><span class="hs-identifier hs-var">dmdTransformThunkDmd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960678"><span class="hs-identifier hs-var">arg</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960673"><span class="hs-identifier hs-var">arg_dmd</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960678"><span class="hs-identifier hs-var">arg</span></a></span><span>
</span><span id="line-192"></span><span>    </span><span class="hs-keyword">in</span><span>
</span><span id="line-193"></span><span class="hs-comment">--    pprTrace &quot;dmdAnal:app&quot; (vcat</span><span>
</span><span id="line-194"></span><span class="hs-comment">--         [ text &quot;dmd =&quot; &lt;+&gt; ppr dmd</span><span>
</span><span id="line-195"></span><span class="hs-comment">--         , text &quot;expr =&quot; &lt;+&gt; ppr (App fun arg)</span><span>
</span><span id="line-196"></span><span class="hs-comment">--         , text &quot;fun dmd_ty =&quot; &lt;+&gt; ppr fun_ty</span><span>
</span><span id="line-197"></span><span class="hs-comment">--         , text &quot;arg dmd =&quot; &lt;+&gt; ppr arg_dmd</span><span>
</span><span id="line-198"></span><span class="hs-comment">--         , text &quot;arg dmd_ty =&quot; &lt;+&gt; ppr arg_ty</span><span>
</span><span id="line-199"></span><span class="hs-comment">--         , text &quot;res dmd_ty =&quot; &lt;+&gt; ppr res_ty</span><span>
</span><span id="line-200"></span><span class="hs-comment">--         , text &quot;overall res dmd_ty =&quot; &lt;+&gt; ppr (res_ty `bothDmdType` arg_ty) ])</span><span>
</span><span id="line-201"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960672"><span class="hs-identifier hs-var">res_ty</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; BothDmdArg -&gt; DmdType
</span><a href="GHC.Types.Demand.html#bothDmdType"><span class="hs-operator hs-var">`bothDmdType`</span></a></span><span> </span><span class="annot"><span class="annottext">BothDmdArg
</span><a href="#local-6989586621680960670"><span class="hs-identifier hs-var">arg_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; CoreExpr -&gt; CoreExpr
forall b. Expr b -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#App"><span class="hs-identifier hs-var">App</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960674"><span class="hs-identifier hs-var">fun'</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960669"><span class="hs-identifier hs-var">arg'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-202"></span><span>
</span><span id="line-203"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal%27"><span class="hs-identifier hs-var">dmdAnal'</span></a></span><span> </span><span id="local-6989586621680960668"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960668"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960667"><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960667"><span class="hs-identifier hs-var">dmd</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Lam"><span class="hs-identifier hs-type">Lam</span></a></span><span> </span><span id="local-6989586621680960665"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960665"><span class="hs-identifier hs-var">var</span></a></span></span><span> </span><span id="local-6989586621680960664"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960664"><span class="hs-identifier hs-var">body</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-204"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Types.Var.html#isTyVar"><span class="hs-identifier hs-var">isTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960665"><span class="hs-identifier hs-var">var</span></a></span><span>
</span><span id="line-205"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span>
</span><span id="line-206"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680960662"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960662"><span class="hs-identifier hs-var">body_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960661"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960661"><span class="hs-identifier hs-var">body'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal"><span class="hs-identifier hs-var">dmdAnal</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960668"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960667"><span class="hs-identifier hs-var">dmd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960664"><span class="hs-identifier hs-var">body</span></a></span><span>
</span><span id="line-207"></span><span>    </span><span class="hs-keyword">in</span><span>
</span><span id="line-208"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960662"><span class="hs-identifier hs-var">body_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Var -&gt; CoreExpr -&gt; CoreExpr
forall b. b -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#Lam"><span class="hs-identifier hs-var">Lam</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960665"><span class="hs-identifier hs-var">var</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960661"><span class="hs-identifier hs-var">body'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-209"></span><span>
</span><span id="line-210"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-211"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680960660"><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960660"><span class="hs-identifier hs-var">body_dmd</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960659"><span class="annot"><span class="annottext">DmdShell
</span><a href="#local-6989586621680960659"><span class="hs-identifier hs-var">defer_and_use</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CleanDemand -&gt; (CleanDemand, DmdShell)
</span><a href="GHC.Types.Demand.html#peelCallDmd"><span class="hs-identifier hs-var">peelCallDmd</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960667"><span class="hs-identifier hs-var">dmd</span></a></span><span>
</span><span id="line-212"></span><span>          </span><span class="hs-comment">-- body_dmd: a demand to analyze the body</span><span>
</span><span id="line-213"></span><span>
</span><span id="line-214"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680960657"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960657"><span class="hs-identifier hs-var">body_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960656"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960656"><span class="hs-identifier hs-var">body'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal"><span class="hs-identifier hs-var">dmdAnal</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960668"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960660"><span class="hs-identifier hs-var">body_dmd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960664"><span class="hs-identifier hs-var">body</span></a></span><span>
</span><span id="line-215"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680960655"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960655"><span class="hs-identifier hs-var">lam_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960654"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960654"><span class="hs-identifier hs-var">var'</span></a></span></span><span class="hs-special">)</span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; Bool -&gt; DmdType -&gt; Var -&gt; (DmdType, Var)
</span><a href="GHC.Core.Opt.DmdAnal.html#annotateLamIdBndr"><span class="hs-identifier hs-var">annotateLamIdBndr</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960668"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Core.Opt.DmdAnal.html#notArgOfDfun"><span class="hs-identifier hs-var">notArgOfDfun</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960657"><span class="hs-identifier hs-var">body_ty</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960665"><span class="hs-identifier hs-var">var</span></a></span><span>
</span><span id="line-216"></span><span>    </span><span class="hs-keyword">in</span><span>
</span><span id="line-217"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdShell -&gt; DmdType -&gt; DmdType
</span><a href="GHC.Types.Demand.html#postProcessUnsat"><span class="hs-identifier hs-var">postProcessUnsat</span></a></span><span> </span><span class="annot"><span class="annottext">DmdShell
</span><a href="#local-6989586621680960659"><span class="hs-identifier hs-var">defer_and_use</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960655"><span class="hs-identifier hs-var">lam_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Var -&gt; CoreExpr -&gt; CoreExpr
forall b. b -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#Lam"><span class="hs-identifier hs-var">Lam</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960654"><span class="hs-identifier hs-var">var'</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960656"><span class="hs-identifier hs-var">body'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-218"></span><span>
</span><span id="line-219"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal%27"><span class="hs-identifier hs-var">dmdAnal'</span></a></span><span> </span><span id="local-6989586621680960650"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960650"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960649"><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960649"><span class="hs-identifier hs-var">dmd</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Case"><span class="hs-identifier hs-type">Case</span></a></span><span> </span><span id="local-6989586621680960647"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960647"><span class="hs-identifier hs-var">scrut</span></a></span></span><span> </span><span id="local-6989586621680960646"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960646"><span class="hs-identifier hs-var">case_bndr</span></a></span></span><span> </span><span id="local-6989586621680960645"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680960645"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#DataAlt"><span class="hs-identifier hs-type">DataAlt</span></a></span><span> </span><span id="local-6989586621680960643"><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680960643"><span class="hs-identifier hs-var">dc</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960642"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960642"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960641"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960641"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-220"></span><span>  </span><span class="hs-comment">-- Only one alternative with a product constructor</span><span>
</span><span id="line-221"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680960640"><span class="annot"><span class="annottext">tycon :: TyCon
</span><a href="#local-6989586621680960640"><span class="hs-identifier hs-var hs-var">tycon</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DataCon -&gt; TyCon
</span><a href="GHC.Core.DataCon.html#dataConTyCon"><span class="hs-identifier hs-var">dataConTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680960643"><span class="hs-identifier hs-var">dc</span></a></span><span>
</span><span id="line-222"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe DataCon -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="../../base/src/Data.Maybe.html#isJust"><span class="hs-identifier hs-var">isJust</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TyCon -&gt; Maybe DataCon
</span><a href="GHC.Core.TyCon.html#isDataProductTyCon_maybe"><span class="hs-identifier hs-var">isDataProductTyCon_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621680960640"><span class="hs-identifier hs-var">tycon</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-223"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span>
</span><span id="line-224"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680960637"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960637"><span class="hs-identifier hs-var">rhs_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960636"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960636"><span class="hs-identifier hs-var">rhs'</span></a></span></span><span class="hs-special">)</span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal"><span class="hs-identifier hs-var">dmdAnal</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960650"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960649"><span class="hs-identifier hs-var">dmd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960641"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-225"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680960635"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960635"><span class="hs-identifier hs-var">alt_ty1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960634"><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960634"><span class="hs-identifier hs-var">dmds</span></a></span></span><span class="hs-special">)</span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; DmdType -&gt; [Var] -&gt; (DmdType, [Demand])
</span><a href="GHC.Core.Opt.DmdAnal.html#findBndrsDmds"><span class="hs-identifier hs-var">findBndrsDmds</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960650"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960637"><span class="hs-identifier hs-var">rhs_ty</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960642"><span class="hs-identifier hs-var">bndrs</span></a></span><span>
</span><span id="line-226"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680960632"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960632"><span class="hs-identifier hs-var">alt_ty2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960631"><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960631"><span class="hs-identifier hs-var">case_bndr_dmd</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; Bool -&gt; DmdType -&gt; Var -&gt; (DmdType, Demand)
</span><a href="GHC.Core.Opt.DmdAnal.html#findBndrDmd"><span class="hs-identifier hs-var">findBndrDmd</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960650"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960635"><span class="hs-identifier hs-var">alt_ty1</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960646"><span class="hs-identifier hs-var">case_bndr</span></a></span><span>
</span><span id="line-227"></span><span>        </span><span id="local-6989586621680960629"><span class="annot"><span class="annottext">id_dmds :: [Demand]
</span><a href="#local-6989586621680960629"><span class="hs-identifier hs-var hs-var">id_dmds</span></a></span></span><span>                  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Demand -&gt; [Demand] -&gt; [Demand]
</span><a href="GHC.Types.Demand.html#addCaseBndrDmd"><span class="hs-identifier hs-var">addCaseBndrDmd</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960631"><span class="hs-identifier hs-var">case_bndr_dmd</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960634"><span class="hs-identifier hs-var">dmds</span></a></span><span>
</span><span id="line-228"></span><span>        </span><span id="local-6989586621680960627"><span class="annot"><span class="annottext">fam_envs :: FamInstEnvs
</span><a href="#local-6989586621680960627"><span class="hs-identifier hs-var hs-var">fam_envs</span></a></span></span><span>                 </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; FamInstEnvs
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_fam_envs"><span class="hs-identifier hs-var hs-var">ae_fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960650"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-229"></span><span>        </span><span id="local-6989586621680960625"><span class="annot"><span class="annottext">alt_ty3 :: DmdType
</span><a href="#local-6989586621680960625"><span class="hs-identifier hs-var hs-var">alt_ty3</span></a></span></span><span>
</span><span id="line-230"></span><span>          </span><span class="hs-comment">-- See Note [Precise exceptions and strictness analysis] in &quot;GHC.Types.Demand&quot;</span><span>
</span><span id="line-231"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">FamInstEnvs -&gt; CoreExpr -&gt; Bool
</span><a href="GHC.Core.Opt.DmdAnal.html#exprMayThrowPreciseException"><span class="hs-identifier hs-var">exprMayThrowPreciseException</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680960627"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960647"><span class="hs-identifier hs-var">scrut</span></a></span><span>
</span><span id="line-232"></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; DmdType
</span><a href="GHC.Types.Demand.html#deferAfterPreciseException"><span class="hs-identifier hs-var">deferAfterPreciseException</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960632"><span class="hs-identifier hs-var">alt_ty2</span></a></span><span>
</span><span id="line-233"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-234"></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960632"><span class="hs-identifier hs-var">alt_ty2</span></a></span><span>
</span><span id="line-235"></span><span>
</span><span id="line-236"></span><span>        </span><span class="hs-comment">-- Compute demand on the scrutinee</span><span>
</span><span id="line-237"></span><span>        </span><span class="hs-comment">-- See Note [Demand on scrutinee of a product case]</span><span>
</span><span id="line-238"></span><span>        </span><span id="local-6989586621680960622"><span class="annot"><span class="annottext">scrut_dmd :: CleanDemand
</span><a href="#local-6989586621680960622"><span class="hs-identifier hs-var hs-var">scrut_dmd</span></a></span></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Demand] -&gt; CleanDemand
</span><a href="GHC.Types.Demand.html#mkProdDmd"><span class="hs-identifier hs-var">mkProdDmd</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960629"><span class="hs-identifier hs-var">id_dmds</span></a></span><span>
</span><span id="line-239"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680960620"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960620"><span class="hs-identifier hs-var">scrut_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960619"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960619"><span class="hs-identifier hs-var">scrut'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal"><span class="hs-identifier hs-var">dmdAnal</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960650"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960622"><span class="hs-identifier hs-var">scrut_dmd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960647"><span class="hs-identifier hs-var">scrut</span></a></span><span>
</span><span id="line-240"></span><span>        </span><span id="local-6989586621680960618"><span class="annot"><span class="annottext">res_ty :: DmdType
</span><a href="#local-6989586621680960618"><span class="hs-identifier hs-var hs-var">res_ty</span></a></span></span><span>             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960625"><span class="hs-identifier hs-var">alt_ty3</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; BothDmdArg -&gt; DmdType
</span><a href="GHC.Types.Demand.html#bothDmdType"><span class="hs-operator hs-var">`bothDmdType`</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; BothDmdArg
</span><a href="GHC.Types.Demand.html#toBothDmdArg"><span class="hs-identifier hs-var">toBothDmdArg</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960620"><span class="hs-identifier hs-var">scrut_ty</span></a></span><span>
</span><span id="line-241"></span><span>        </span><span id="local-6989586621680960616"><span class="annot"><span class="annottext">case_bndr' :: Var
</span><a href="#local-6989586621680960616"><span class="hs-identifier hs-var hs-var">case_bndr'</span></a></span></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Demand -&gt; Var
</span><a href="GHC.Types.Id.html#setIdDemandInfo"><span class="hs-identifier hs-var">setIdDemandInfo</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960646"><span class="hs-identifier hs-var">case_bndr</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960631"><span class="hs-identifier hs-var">case_bndr_dmd</span></a></span><span>
</span><span id="line-242"></span><span>        </span><span id="local-6989586621680960614"><span class="annot"><span class="annottext">bndrs' :: [Var]
</span><a href="#local-6989586621680960614"><span class="hs-identifier hs-var hs-var">bndrs'</span></a></span></span><span>             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Var] -&gt; [Demand] -&gt; [Var]
</span><a href="GHC.Core.Opt.DmdAnal.html#setBndrsDemandInfo"><span class="hs-identifier hs-var">setBndrsDemandInfo</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960642"><span class="hs-identifier hs-var">bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960629"><span class="hs-identifier hs-var">id_dmds</span></a></span><span>
</span><span id="line-243"></span><span>    </span><span class="hs-keyword">in</span><span>
</span><span id="line-244"></span><span class="hs-comment">--    pprTrace &quot;dmdAnal:Case1&quot; (vcat [ text &quot;scrut&quot; &lt;+&gt; ppr scrut</span><span>
</span><span id="line-245"></span><span class="hs-comment">--                                   , text &quot;dmd&quot; &lt;+&gt; ppr dmd</span><span>
</span><span id="line-246"></span><span class="hs-comment">--                                   , text &quot;case_bndr_dmd&quot; &lt;+&gt; ppr (idDemandInfo case_bndr')</span><span>
</span><span id="line-247"></span><span class="hs-comment">--                                   , text &quot;id_dmds&quot; &lt;+&gt; ppr id_dmds</span><span>
</span><span id="line-248"></span><span class="hs-comment">--                                   , text &quot;scrut_dmd&quot; &lt;+&gt; ppr scrut_dmd</span><span>
</span><span id="line-249"></span><span class="hs-comment">--                                   , text &quot;scrut_ty&quot; &lt;+&gt; ppr scrut_ty</span><span>
</span><span id="line-250"></span><span class="hs-comment">--                                   , text &quot;alt_ty&quot; &lt;+&gt; ppr alt_ty2</span><span>
</span><span id="line-251"></span><span class="hs-comment">--                                   , text &quot;res_ty&quot; &lt;+&gt; ppr res_ty ]) $</span><span>
</span><span id="line-252"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960618"><span class="hs-identifier hs-var">res_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; Var -&gt; Type -&gt; [Alt Var] -&gt; CoreExpr
forall b. Expr b -&gt; b -&gt; Type -&gt; [Alt b] -&gt; Expr b
</span><a href="GHC.Core.html#Case"><span class="hs-identifier hs-var">Case</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960619"><span class="hs-identifier hs-var">scrut'</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960616"><span class="hs-identifier hs-var">case_bndr'</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680960645"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><span class="annottext">DataCon -&gt; AltCon
</span><a href="GHC.Core.html#DataAlt"><span class="hs-identifier hs-var">DataAlt</span></a></span><span> </span><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680960643"><span class="hs-identifier hs-var">dc</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960614"><span class="hs-identifier hs-var">bndrs'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960636"><span class="hs-identifier hs-var">rhs'</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-253"></span><span>
</span><span id="line-254"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal%27"><span class="hs-identifier hs-var">dmdAnal'</span></a></span><span> </span><span id="local-6989586621680960612"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960612"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960611"><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960611"><span class="hs-identifier hs-var">dmd</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Case"><span class="hs-identifier hs-type">Case</span></a></span><span> </span><span id="local-6989586621680960610"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960610"><span class="hs-identifier hs-var">scrut</span></a></span></span><span> </span><span id="local-6989586621680960609"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960609"><span class="hs-identifier hs-var">case_bndr</span></a></span></span><span> </span><span id="local-6989586621680960608"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680960608"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span id="local-6989586621680960607"><span class="annot"><span class="annottext">[Alt Var]
</span><a href="#local-6989586621680960607"><span class="hs-identifier hs-var">alts</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-255"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span>      </span><span class="hs-comment">-- Case expression with multiple alternatives</span><span>
</span><span id="line-256"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680960606"><span class="annot"><span class="annottext">[DmdType]
</span><a href="#local-6989586621680960606"><span class="hs-identifier hs-var">alt_tys</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960605"><span class="annot"><span class="annottext">[Alt Var]
</span><a href="#local-6989586621680960605"><span class="hs-identifier hs-var">alts'</span></a></span></span><span class="hs-special">)</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Alt Var -&gt; (DmdType, Alt Var))
-&gt; [Alt Var] -&gt; ([DmdType], [Alt Var])
forall a b c. (a -&gt; (b, c)) -&gt; [a] -&gt; ([b], [c])
</span><a href="GHC.Utils.Misc.html#mapAndUnzip"><span class="hs-identifier hs-var">mapAndUnzip</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">AnalEnv -&gt; CleanDemand -&gt; Var -&gt; Alt Var -&gt; (DmdType, Alt Var)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalAlt"><span class="hs-identifier hs-var">dmdAnalAlt</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960612"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960611"><span class="hs-identifier hs-var">dmd</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960609"><span class="hs-identifier hs-var">case_bndr</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Alt Var]
</span><a href="#local-6989586621680960607"><span class="hs-identifier hs-var">alts</span></a></span><span>
</span><span id="line-257"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680960602"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960602"><span class="hs-identifier hs-var">scrut_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960601"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960601"><span class="hs-identifier hs-var">scrut'</span></a></span></span><span class="hs-special">)</span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal"><span class="hs-identifier hs-var">dmdAnal</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960612"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="GHC.Types.Demand.html#cleanEvalDmd"><span class="hs-identifier hs-var">cleanEvalDmd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960610"><span class="hs-identifier hs-var">scrut</span></a></span><span>
</span><span id="line-258"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680960599"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960599"><span class="hs-identifier hs-var">alt_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960598"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960598"><span class="hs-identifier hs-var">case_bndr'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; DmdType -&gt; Var -&gt; (DmdType, Var)
</span><a href="GHC.Core.Opt.DmdAnal.html#annotateBndr"><span class="hs-identifier hs-var">annotateBndr</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960612"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(DmdType -&gt; DmdType -&gt; DmdType) -&gt; DmdType -&gt; [DmdType] -&gt; DmdType
forall (t :: * -&gt; *) a b.
Foldable t =&gt;
(a -&gt; b -&gt; b) -&gt; b -&gt; t a -&gt; b
</span><a href="../../base/src/Data.Foldable.html#foldr"><span class="hs-identifier hs-var">foldr</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; DmdType -&gt; DmdType
</span><a href="GHC.Types.Demand.html#lubDmdType"><span class="hs-identifier hs-var">lubDmdType</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="GHC.Types.Demand.html#botDmdType"><span class="hs-identifier hs-var">botDmdType</span></a></span><span> </span><span class="annot"><span class="annottext">[DmdType]
</span><a href="#local-6989586621680960606"><span class="hs-identifier hs-var">alt_tys</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960609"><span class="hs-identifier hs-var">case_bndr</span></a></span><span>
</span><span id="line-259"></span><span>                               </span><span class="hs-comment">-- NB: Base case is botDmdType, for empty case alternatives</span><span>
</span><span id="line-260"></span><span>                               </span><span class="hs-comment">--     This is a unit for lubDmdType, and the right result</span><span>
</span><span id="line-261"></span><span>                               </span><span class="hs-comment">--     when there really are no alternatives</span><span>
</span><span id="line-262"></span><span>        </span><span id="local-6989586621680960593"><span class="annot"><span class="annottext">fam_envs :: FamInstEnvs
</span><a href="#local-6989586621680960593"><span class="hs-identifier hs-var hs-var">fam_envs</span></a></span></span><span>             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; FamInstEnvs
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_fam_envs"><span class="hs-identifier hs-var hs-var">ae_fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960612"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-263"></span><span>        </span><span id="local-6989586621680960592"><span class="annot"><span class="annottext">alt_ty2 :: DmdType
</span><a href="#local-6989586621680960592"><span class="hs-identifier hs-var hs-var">alt_ty2</span></a></span></span><span>
</span><span id="line-264"></span><span>          </span><span class="hs-comment">-- See Note [Precise exceptions and strictness analysis] in &quot;GHC.Types.Demand&quot;</span><span>
</span><span id="line-265"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">FamInstEnvs -&gt; CoreExpr -&gt; Bool
</span><a href="GHC.Core.Opt.DmdAnal.html#exprMayThrowPreciseException"><span class="hs-identifier hs-var">exprMayThrowPreciseException</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680960593"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960610"><span class="hs-identifier hs-var">scrut</span></a></span><span>
</span><span id="line-266"></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; DmdType
</span><a href="GHC.Types.Demand.html#deferAfterPreciseException"><span class="hs-identifier hs-var">deferAfterPreciseException</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960599"><span class="hs-identifier hs-var">alt_ty</span></a></span><span>
</span><span id="line-267"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-268"></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960599"><span class="hs-identifier hs-var">alt_ty</span></a></span><span>
</span><span id="line-269"></span><span>        </span><span id="local-6989586621680960591"><span class="annot"><span class="annottext">res_ty :: DmdType
</span><a href="#local-6989586621680960591"><span class="hs-identifier hs-var hs-var">res_ty</span></a></span></span><span>               </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960592"><span class="hs-identifier hs-var">alt_ty2</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; BothDmdArg -&gt; DmdType
</span><a href="GHC.Types.Demand.html#bothDmdType"><span class="hs-operator hs-var">`bothDmdType`</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; BothDmdArg
</span><a href="GHC.Types.Demand.html#toBothDmdArg"><span class="hs-identifier hs-var">toBothDmdArg</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960602"><span class="hs-identifier hs-var">scrut_ty</span></a></span><span>
</span><span id="line-270"></span><span>
</span><span id="line-271"></span><span>    </span><span class="hs-keyword">in</span><span>
</span><span id="line-272"></span><span class="hs-comment">--    pprTrace &quot;dmdAnal:Case2&quot; (vcat [ text &quot;scrut&quot; &lt;+&gt; ppr scrut</span><span>
</span><span id="line-273"></span><span class="hs-comment">--                                   , text &quot;scrut_ty&quot; &lt;+&gt; ppr scrut_ty</span><span>
</span><span id="line-274"></span><span class="hs-comment">--                                   , text &quot;alt_tys&quot; &lt;+&gt; ppr alt_tys</span><span>
</span><span id="line-275"></span><span class="hs-comment">--                                   , text &quot;alt_ty2&quot; &lt;+&gt; ppr alt_ty2</span><span>
</span><span id="line-276"></span><span class="hs-comment">--                                   , text &quot;res_ty&quot; &lt;+&gt; ppr res_ty ]) $</span><span>
</span><span id="line-277"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960591"><span class="hs-identifier hs-var">res_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; Var -&gt; Type -&gt; [Alt Var] -&gt; CoreExpr
forall b. Expr b -&gt; b -&gt; Type -&gt; [Alt b] -&gt; Expr b
</span><a href="GHC.Core.html#Case"><span class="hs-identifier hs-var">Case</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960601"><span class="hs-identifier hs-var">scrut'</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960598"><span class="hs-identifier hs-var">case_bndr'</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680960608"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="annot"><span class="annottext">[Alt Var]
</span><a href="#local-6989586621680960605"><span class="hs-identifier hs-var">alts'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-278"></span><span>
</span><span id="line-279"></span><span class="hs-comment">-- Let bindings can be processed in two ways:</span><span>
</span><span id="line-280"></span><span class="hs-comment">-- Down (RHS before body) or Up (body before RHS).</span><span>
</span><span id="line-281"></span><span class="hs-comment">-- The following case handle the up variant.</span><span>
</span><span id="line-282"></span><span class="hs-comment">--</span><span>
</span><span id="line-283"></span><span class="hs-comment">-- It is very simple. For  let x = rhs in body</span><span>
</span><span id="line-284"></span><span class="hs-comment">--   * Demand-analyse 'body' in the current environment</span><span>
</span><span id="line-285"></span><span class="hs-comment">--   * Find the demand, 'rhs_dmd' placed on 'x' by 'body'</span><span>
</span><span id="line-286"></span><span class="hs-comment">--   * Demand-analyse 'rhs' in 'rhs_dmd'</span><span>
</span><span id="line-287"></span><span class="hs-comment">--</span><span>
</span><span id="line-288"></span><span class="hs-comment">-- This is used for a non-recursive local let without manifest lambdas.</span><span>
</span><span id="line-289"></span><span class="hs-comment">-- This is the LetUp rule in the paper &#8220;Higher-Order Cardinality Analysis&#8221;.</span><span>
</span><span id="line-290"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal%27"><span class="hs-identifier hs-var">dmdAnal'</span></a></span><span> </span><span id="local-6989586621680960590"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960590"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960589"><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960589"><span class="hs-identifier hs-var">dmd</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Let"><span class="hs-identifier hs-type">Let</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#NonRec"><span class="hs-identifier hs-type">NonRec</span></a></span><span> </span><span id="local-6989586621680960587"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960587"><span class="hs-identifier hs-var">id</span></a></span></span><span> </span><span id="local-6989586621680960586"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960586"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680960585"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960585"><span class="hs-identifier hs-var">body</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-291"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Core.Opt.DmdAnal.html#useLetUp"><span class="hs-identifier hs-var">useLetUp</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960587"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-292"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960583"><span class="hs-identifier hs-var">final_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreBind -&gt; CoreExpr -&gt; CoreExpr
forall b. Bind b -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#Let"><span class="hs-identifier hs-var">Let</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; CoreExpr -&gt; CoreBind
forall b. b -&gt; Expr b -&gt; Bind b
</span><a href="GHC.Core.html#NonRec"><span class="hs-identifier hs-var">NonRec</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960582"><span class="hs-identifier hs-var">id'</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960581"><span class="hs-identifier hs-var">rhs'</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960580"><span class="hs-identifier hs-var">body'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-293"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-294"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680960579"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960579"><span class="hs-identifier hs-var">body_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960580"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960580"><span class="hs-identifier hs-var">body'</span></a></span></span><span class="hs-special">)</span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal"><span class="hs-identifier hs-var">dmdAnal</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960590"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960589"><span class="hs-identifier hs-var">dmd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960585"><span class="hs-identifier hs-var">body</span></a></span><span>
</span><span id="line-295"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680960578"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960578"><span class="hs-identifier hs-var">body_ty'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960577"><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960577"><span class="hs-identifier hs-var">id_dmd</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; Bool -&gt; DmdType -&gt; Var -&gt; (DmdType, Demand)
</span><a href="GHC.Core.Opt.DmdAnal.html#findBndrDmd"><span class="hs-identifier hs-var">findBndrDmd</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960590"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Core.Opt.DmdAnal.html#notArgOfDfun"><span class="hs-identifier hs-var">notArgOfDfun</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960579"><span class="hs-identifier hs-var">body_ty</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960587"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-296"></span><span>    </span><span id="local-6989586621680960582"><span class="annot"><span class="annottext">id' :: Var
</span><a href="#local-6989586621680960582"><span class="hs-identifier hs-var hs-var">id'</span></a></span></span><span>                </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Demand -&gt; Var
</span><a href="GHC.Types.Id.html#setIdDemandInfo"><span class="hs-identifier hs-var">setIdDemandInfo</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960587"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960577"><span class="hs-identifier hs-var">id_dmd</span></a></span><span>
</span><span id="line-297"></span><span>
</span><span id="line-298"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680960576"><span class="annot"><span class="annottext">BothDmdArg
</span><a href="#local-6989586621680960576"><span class="hs-identifier hs-var">rhs_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960581"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960581"><span class="hs-identifier hs-var">rhs'</span></a></span></span><span class="hs-special">)</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; Demand -&gt; CoreExpr -&gt; (BothDmdArg, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalStar"><span class="hs-identifier hs-var">dmdAnalStar</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960590"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreExpr -&gt; Demand -&gt; Demand
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdTransformThunkDmd"><span class="hs-identifier hs-var">dmdTransformThunkDmd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960586"><span class="hs-identifier hs-var">rhs</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960577"><span class="hs-identifier hs-var">id_dmd</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960586"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-299"></span><span>    </span><span id="local-6989586621680960583"><span class="annot"><span class="annottext">final_ty :: DmdType
</span><a href="#local-6989586621680960583"><span class="hs-identifier hs-var hs-var">final_ty</span></a></span></span><span>           </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960578"><span class="hs-identifier hs-var">body_ty'</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; BothDmdArg -&gt; DmdType
</span><a href="GHC.Types.Demand.html#bothDmdType"><span class="hs-operator hs-var">`bothDmdType`</span></a></span><span> </span><span class="annot"><span class="annottext">BothDmdArg
</span><a href="#local-6989586621680960576"><span class="hs-identifier hs-var">rhs_ty</span></a></span><span>
</span><span id="line-300"></span><span>
</span><span id="line-301"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal%27"><span class="hs-identifier hs-var">dmdAnal'</span></a></span><span> </span><span id="local-6989586621680960575"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960575"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960574"><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960574"><span class="hs-identifier hs-var">dmd</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Let"><span class="hs-identifier hs-type">Let</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#NonRec"><span class="hs-identifier hs-type">NonRec</span></a></span><span> </span><span id="local-6989586621680960573"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960573"><span class="hs-identifier hs-var">id</span></a></span></span><span> </span><span id="local-6989586621680960572"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960572"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680960571"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960571"><span class="hs-identifier hs-var">body</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-302"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960570"><span class="hs-identifier hs-var">body_ty2</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreBind -&gt; CoreExpr -&gt; CoreExpr
forall b. Bind b -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#Let"><span class="hs-identifier hs-var">Let</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; CoreExpr -&gt; CoreBind
forall b. b -&gt; Expr b -&gt; Bind b
</span><a href="GHC.Core.html#NonRec"><span class="hs-identifier hs-var">NonRec</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960569"><span class="hs-identifier hs-var">id2</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960568"><span class="hs-identifier hs-var">rhs'</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960567"><span class="hs-identifier hs-var">body'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-303"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-304"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680960566"><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960566"><span class="hs-identifier hs-var">lazy_fv</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960565"><span class="annot"><span class="annottext">StrictSig
</span><a href="#local-6989586621680960565"><span class="hs-identifier hs-var">sig</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960568"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960568"><span class="hs-identifier hs-var">rhs'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe [Var]
-&gt; AnalEnv
-&gt; CleanDemand
-&gt; Var
-&gt; CoreExpr
-&gt; (DmdEnv, StrictSig, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalRhsLetDown"><span class="hs-identifier hs-var">dmdAnalRhsLetDown</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe [Var]
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960575"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960574"><span class="hs-identifier hs-var">dmd</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960573"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960572"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-305"></span><span>    </span><span id="local-6989586621680960564"><span class="annot"><span class="annottext">id1 :: Var
</span><a href="#local-6989586621680960564"><span class="hs-identifier hs-var hs-var">id1</span></a></span></span><span>                  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var -&gt; StrictSig -&gt; Var
</span><a href="GHC.Types.Id.html#setIdStrictness"><span class="hs-identifier hs-var">setIdStrictness</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960573"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">StrictSig
</span><a href="#local-6989586621680960565"><span class="hs-identifier hs-var">sig</span></a></span><span>
</span><span id="line-306"></span><span>    </span><span id="local-6989586621680960563"><span class="annot"><span class="annottext">env1 :: AnalEnv
</span><a href="#local-6989586621680960563"><span class="hs-identifier hs-var hs-var">env1</span></a></span></span><span>                 </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TopLevelFlag -&gt; AnalEnv -&gt; Var -&gt; StrictSig -&gt; AnalEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#extendAnalEnv"><span class="hs-identifier hs-var">extendAnalEnv</span></a></span><span> </span><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="GHC.Types.Basic.html#NotTopLevel"><span class="hs-identifier hs-var">NotTopLevel</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960575"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960573"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">StrictSig
</span><a href="#local-6989586621680960565"><span class="hs-identifier hs-var">sig</span></a></span><span>
</span><span id="line-307"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680960561"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960561"><span class="hs-identifier hs-var">body_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960567"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960567"><span class="hs-identifier hs-var">body'</span></a></span></span><span class="hs-special">)</span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal"><span class="hs-identifier hs-var">dmdAnal</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960563"><span class="hs-identifier hs-var">env1</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960574"><span class="hs-identifier hs-var">dmd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960571"><span class="hs-identifier hs-var">body</span></a></span><span>
</span><span id="line-308"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680960560"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960560"><span class="hs-identifier hs-var">body_ty1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960569"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960569"><span class="hs-identifier hs-var">id2</span></a></span></span><span class="hs-special">)</span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; DmdType -&gt; Var -&gt; (DmdType, Var)
</span><a href="GHC.Core.Opt.DmdAnal.html#annotateBndr"><span class="hs-identifier hs-var">annotateBndr</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960575"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960561"><span class="hs-identifier hs-var">body_ty</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960564"><span class="hs-identifier hs-var">id1</span></a></span><span>
</span><span id="line-309"></span><span>    </span><span id="local-6989586621680960570"><span class="annot"><span class="annottext">body_ty2 :: DmdType
</span><a href="#local-6989586621680960570"><span class="hs-identifier hs-var hs-var">body_ty2</span></a></span></span><span>             </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; DmdEnv -&gt; DmdType
</span><a href="GHC.Core.Opt.DmdAnal.html#addLazyFVs"><span class="hs-identifier hs-var">addLazyFVs</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960560"><span class="hs-identifier hs-var">body_ty1</span></a></span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960566"><span class="hs-identifier hs-var">lazy_fv</span></a></span><span> </span><span class="hs-comment">-- see Note [Lazy and unleashable free variables]</span><span>
</span><span id="line-310"></span><span>
</span><span id="line-311"></span><span>        </span><span class="hs-comment">-- If the actual demand is better than the vanilla call</span><span>
</span><span id="line-312"></span><span>        </span><span class="hs-comment">-- demand, you might think that we might do better to re-analyse</span><span>
</span><span id="line-313"></span><span>        </span><span class="hs-comment">-- the RHS with the stronger demand.</span><span>
</span><span id="line-314"></span><span>        </span><span class="hs-comment">-- But (a) That seldom happens, because it means that *every* path in</span><span>
</span><span id="line-315"></span><span>        </span><span class="hs-comment">--         the body of the let has to use that stronger demand</span><span>
</span><span id="line-316"></span><span>        </span><span class="hs-comment">-- (b) It often happens temporarily in when fixpointing, because</span><span>
</span><span id="line-317"></span><span>        </span><span class="hs-comment">--     the recursive function at first seems to place a massive demand.</span><span>
</span><span id="line-318"></span><span>        </span><span class="hs-comment">--     But we don't want to go to extra work when the function will</span><span>
</span><span id="line-319"></span><span>        </span><span class="hs-comment">--     probably iterate to something less demanding.</span><span>
</span><span id="line-320"></span><span>        </span><span class="hs-comment">-- In practice, all the times the actual demand on id2 is more than</span><span>
</span><span id="line-321"></span><span>        </span><span class="hs-comment">-- the vanilla call demand seem to be due to (b).  So we don't</span><span>
</span><span id="line-322"></span><span>        </span><span class="hs-comment">-- bother to re-analyse the RHS.</span><span>
</span><span id="line-323"></span><span>
</span><span id="line-324"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal%27"><span class="hs-identifier hs-var">dmdAnal'</span></a></span><span> </span><span id="local-6989586621680960558"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960558"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960557"><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960557"><span class="hs-identifier hs-var">dmd</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Let"><span class="hs-identifier hs-type">Let</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Rec"><span class="hs-identifier hs-type">Rec</span></a></span><span> </span><span id="local-6989586621680960556"><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960556"><span class="hs-identifier hs-var">pairs</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680960555"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960555"><span class="hs-identifier hs-var">body</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-325"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span>
</span><span id="line-326"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680960554"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960554"><span class="hs-identifier hs-var">env'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960553"><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960553"><span class="hs-identifier hs-var">lazy_fv</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960552"><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960552"><span class="hs-identifier hs-var">pairs'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TopLevelFlag
-&gt; AnalEnv
-&gt; CleanDemand
-&gt; [(Var, CoreExpr)]
-&gt; (AnalEnv, DmdEnv, [(Var, CoreExpr)])
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdFix"><span class="hs-identifier hs-var">dmdFix</span></a></span><span> </span><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="GHC.Types.Basic.html#NotTopLevel"><span class="hs-identifier hs-var">NotTopLevel</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960558"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960557"><span class="hs-identifier hs-var">dmd</span></a></span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960556"><span class="hs-identifier hs-var">pairs</span></a></span><span>
</span><span id="line-327"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680960551"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960551"><span class="hs-identifier hs-var">body_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960550"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960550"><span class="hs-identifier hs-var">body'</span></a></span></span><span class="hs-special">)</span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal"><span class="hs-identifier hs-var">dmdAnal</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960554"><span class="hs-identifier hs-var">env'</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960557"><span class="hs-identifier hs-var">dmd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960555"><span class="hs-identifier hs-var">body</span></a></span><span>
</span><span id="line-328"></span><span>        </span><span id="local-6989586621680960549"><span class="annot"><span class="annottext">body_ty1 :: DmdType
</span><a href="#local-6989586621680960549"><span class="hs-identifier hs-var hs-var">body_ty1</span></a></span></span><span>                </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; [Var] -&gt; DmdType
</span><a href="GHC.Core.Opt.DmdAnal.html#deleteFVs"><span class="hs-identifier hs-var">deleteFVs</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960551"><span class="hs-identifier hs-var">body_ty</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">((Var, CoreExpr) -&gt; Var) -&gt; [(Var, CoreExpr)] -&gt; [Var]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">(Var, CoreExpr) -&gt; Var
forall a b. (a, b) -&gt; a
</span><a href="../../base/src/Data.Tuple.html#fst"><span class="hs-identifier hs-var">fst</span></a></span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960556"><span class="hs-identifier hs-var">pairs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-329"></span><span>        </span><span id="local-6989586621680960547"><span class="annot"><span class="annottext">body_ty2 :: DmdType
</span><a href="#local-6989586621680960547"><span class="hs-identifier hs-var hs-var">body_ty2</span></a></span></span><span>                </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; DmdEnv -&gt; DmdType
</span><a href="GHC.Core.Opt.DmdAnal.html#addLazyFVs"><span class="hs-identifier hs-var">addLazyFVs</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960549"><span class="hs-identifier hs-var">body_ty1</span></a></span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960553"><span class="hs-identifier hs-var">lazy_fv</span></a></span><span> </span><span class="hs-comment">-- see Note [Lazy and unleashable free variables]</span><span>
</span><span id="line-330"></span><span>    </span><span class="hs-keyword">in</span><span>
</span><span id="line-331"></span><span>    </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960547"><span class="hs-identifier hs-var">body_ty2</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; (DmdType, CoreExpr) -&gt; (DmdType, CoreExpr)
</span><span class="hs-operator hs-var">`seq`</span></span><span>
</span><span id="line-332"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960547"><span class="hs-identifier hs-var">body_ty2</span></a></span><span class="hs-special">,</span><span>  </span><span class="annot"><span class="annottext">CoreBind -&gt; CoreExpr -&gt; CoreExpr
forall b. Bind b -&gt; Expr b -&gt; Expr b
</span><a href="GHC.Core.html#Let"><span class="hs-identifier hs-var">Let</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[(Var, CoreExpr)] -&gt; CoreBind
forall b. [(b, Expr b)] -&gt; Bind b
</span><a href="GHC.Core.html#Rec"><span class="hs-identifier hs-var">Rec</span></a></span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960552"><span class="hs-identifier hs-var">pairs'</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960550"><span class="hs-identifier hs-var">body'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-333"></span><span>
</span><span id="line-334"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#deleteFVs"><span class="hs-identifier hs-type">deleteFVs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span>
</span><span id="line-335"></span><span id="deleteFVs"><span class="annot"><span class="annottext">deleteFVs :: DmdType -&gt; [Var] -&gt; DmdType
</span><a href="GHC.Core.Opt.DmdAnal.html#deleteFVs"><span class="hs-identifier hs-var hs-var">deleteFVs</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span> </span><span id="local-6989586621680960545"><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960545"><span class="hs-identifier hs-var">fvs</span></a></span></span><span> </span><span id="local-6989586621680960544"><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960544"><span class="hs-identifier hs-var">dmds</span></a></span></span><span> </span><span id="local-6989586621680960543"><span class="annot"><span class="annottext">Divergence
</span><a href="#local-6989586621680960543"><span class="hs-identifier hs-var">res</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680960542"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960542"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span>
</span><span id="line-336"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdEnv -&gt; [Demand] -&gt; Divergence -&gt; DmdType
</span><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-var">DmdType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdEnv -&gt; [Var] -&gt; DmdEnv
forall a. VarEnv a -&gt; [Var] -&gt; VarEnv a
</span><a href="GHC.Types.Var.Env.html#delVarEnvList"><span class="hs-identifier hs-var">delVarEnvList</span></a></span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960545"><span class="hs-identifier hs-var">fvs</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960542"><span class="hs-identifier hs-var">bndrs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960544"><span class="hs-identifier hs-var">dmds</span></a></span><span> </span><span class="annot"><span class="annottext">Divergence
</span><a href="#local-6989586621680960543"><span class="hs-identifier hs-var">res</span></a></span><span>
</span><span id="line-337"></span><span>
</span><span id="line-338"></span><span class="hs-comment">-- | A simple, syntactic analysis of whether an expression MAY throw a precise</span><span>
</span><span id="line-339"></span><span class="hs-comment">-- exception when evaluated. It's always sound to return 'True'.</span><span>
</span><span id="line-340"></span><span class="hs-comment">-- See Note [Which scrutinees may throw precise exceptions].</span><span>
</span><span id="line-341"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#exprMayThrowPreciseException"><span class="hs-identifier hs-type">exprMayThrowPreciseException</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier hs-type">FamInstEnvs</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-342"></span><span id="exprMayThrowPreciseException"><span class="annot"><span class="annottext">exprMayThrowPreciseException :: FamInstEnvs -&gt; CoreExpr -&gt; Bool
</span><a href="GHC.Core.Opt.DmdAnal.html#exprMayThrowPreciseException"><span class="hs-identifier hs-var hs-var">exprMayThrowPreciseException</span></a></span></span><span> </span><span id="local-6989586621680960540"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680960540"><span class="hs-identifier hs-var">envs</span></a></span></span><span> </span><span id="local-6989586621680960539"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960539"><span class="hs-identifier hs-var">e</span></a></span></span><span>
</span><span id="line-343"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FamInstEnvs -&gt; Type -&gt; Bool
</span><a href="GHC.Core.Opt.DmdAnal.html#forcesRealWorld"><span class="hs-identifier hs-var">forcesRealWorld</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680960540"><span class="hs-identifier hs-var">envs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreExpr -&gt; Type
</span><a href="GHC.Core.Utils.html#exprType"><span class="hs-identifier hs-var">exprType</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960539"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-344"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="hs-comment">-- 1. in the Note</span><span>
</span><span id="line-345"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680960537"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960537"><span class="hs-identifier hs-var">f</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; (CoreExpr, [CoreExpr])
forall b. Expr b -&gt; (Expr b, [Expr b])
</span><a href="GHC.Core.html#collectArgs"><span class="hs-identifier hs-var">collectArgs</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960539"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-346"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680960535"><span class="annot"><span class="annottext">PrimOp
</span><a href="#local-6989586621680960535"><span class="hs-identifier hs-var">op</span></a></span></span><span>    </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Maybe PrimOp
</span><a href="GHC.Types.Id.html#isPrimOpId_maybe"><span class="hs-identifier hs-var">isPrimOpId_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960537"><span class="hs-identifier hs-var">f</span></a></span><span>
</span><span id="line-347"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">PrimOp
</span><a href="#local-6989586621680960535"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">PrimOp -&gt; PrimOp -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">/=</span></span><span> </span><span class="annot"><span class="annottext">PrimOp
</span><a href="GHC.Builtin.PrimOps.html#RaiseIOOp"><span class="hs-identifier hs-var">RaiseIOOp</span></a></span><span>
</span><span id="line-348"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="hs-comment">-- 2. in the Note</span><span>
</span><span id="line-349"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span id="local-6989586621680960531"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960531"><span class="hs-identifier hs-var">f</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[CoreExpr]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; (CoreExpr, [CoreExpr])
forall b. Expr b -&gt; (Expr b, [Expr b])
</span><a href="GHC.Core.html#collectArgs"><span class="hs-identifier hs-var">collectArgs</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960539"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-350"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680960530"><span class="annot"><span class="annottext">ForeignCall
</span><a href="#local-6989586621680960530"><span class="hs-identifier hs-var">fcall</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Maybe ForeignCall
</span><a href="GHC.Types.Id.html#isFCallId_maybe"><span class="hs-identifier hs-var">isFCallId_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960531"><span class="hs-identifier hs-var">f</span></a></span><span>
</span><span id="line-351"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ForeignCall -&gt; Bool
</span><a href="GHC.Types.ForeignCall.html#isSafeForeignCall"><span class="hs-identifier hs-var">isSafeForeignCall</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignCall
</span><a href="#local-6989586621680960530"><span class="hs-identifier hs-var">fcall</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-352"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="hs-comment">-- 3. in the Note</span><span>
</span><span id="line-353"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-354"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>  </span><span class="hs-comment">-- _. in the Note</span><span>
</span><span id="line-355"></span><span>
</span><span id="line-356"></span><span class="hs-comment">-- | Recognises types that are</span><span>
</span><span id="line-357"></span><span class="hs-comment">--    * @State# RealWorld@</span><span>
</span><span id="line-358"></span><span class="hs-comment">--    * Unboxed tuples with a @State# RealWorld@ field</span><span>
</span><span id="line-359"></span><span class="hs-comment">-- modulo coercions. This will detect 'IO' actions (even post Nested CPR! See</span><span>
</span><span id="line-360"></span><span class="hs-comment">-- T13380e) and user-written variants thereof by their type.</span><span>
</span><span id="line-361"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#forcesRealWorld"><span class="hs-identifier hs-type">forcesRealWorld</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier hs-type">FamInstEnvs</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-362"></span><span id="forcesRealWorld"><span class="annot"><span class="annottext">forcesRealWorld :: FamInstEnvs -&gt; Type -&gt; Bool
</span><a href="GHC.Core.Opt.DmdAnal.html#forcesRealWorld"><span class="hs-identifier hs-var hs-var">forcesRealWorld</span></a></span></span><span> </span><span id="local-6989586621680960528"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680960528"><span class="hs-identifier hs-var">fam_envs</span></a></span></span><span> </span><span id="local-6989586621680960527"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680960527"><span class="hs-identifier hs-var">ty</span></a></span></span><span>
</span><span id="line-363"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680960527"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="annot"><span class="annottext">Type -&gt; Type -&gt; Bool
</span><a href="GHC.Core.Type.html#eqType"><span class="hs-operator hs-var">`eqType`</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="GHC.Builtin.Types.Prim.html#realWorldStatePrimTy"><span class="hs-identifier hs-var">realWorldStatePrimTy</span></a></span><span>
</span><span id="line-364"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-365"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Opt.WorkWrap.Utils.html#DataConAppContext"><span class="hs-identifier hs-type">DataConAppContext</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">dcac_dc :: DataConAppContext -&gt; DataCon
</span><a href="GHC.Core.Opt.WorkWrap.Utils.html#dcac_dc"><span class="hs-identifier hs-var">dcac_dc</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680960523"><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680960523"><span class="hs-identifier hs-var">dc</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dcac_arg_tys :: DataConAppContext -&gt; [(Scaled Type, StrictnessMark)]
</span><a href="GHC.Core.Opt.WorkWrap.Utils.html#dcac_arg_tys"><span class="hs-identifier hs-var">dcac_arg_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680960521"><span class="annot"><span class="annottext">[(Scaled Type, StrictnessMark)]
</span><a href="#local-6989586621680960521"><span class="hs-identifier hs-var">field_tys</span></a></span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-366"></span><span>      </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FamInstEnvs -&gt; Type -&gt; Maybe DataConAppContext
</span><a href="GHC.Core.Opt.WorkWrap.Utils.html#deepSplitProductType_maybe"><span class="hs-identifier hs-var">deepSplitProductType_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680960528"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680960527"><span class="hs-identifier hs-var">ty</span></a></span><span>
</span><span id="line-367"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">DataCon -&gt; Bool
</span><a href="GHC.Core.DataCon.html#isUnboxedTupleCon"><span class="hs-identifier hs-var">isUnboxedTupleCon</span></a></span><span> </span><span class="annot"><span class="annottext">DataCon
</span><a href="#local-6989586621680960523"><span class="hs-identifier hs-var">dc</span></a></span><span>
</span><span id="line-368"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">((Scaled Type, StrictnessMark) -&gt; Bool)
-&gt; [(Scaled Type, StrictnessMark)] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; (a -&gt; Bool) -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#any"><span class="hs-identifier hs-var">any</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-special">(</span><span id="local-6989586621680960517"><span class="annot"><span class="annottext">Scaled Type
</span><a href="#local-6989586621680960517"><span class="hs-identifier hs-var">ty</span></a></span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">StrictnessMark
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Scaled Type -&gt; Type
forall a. Scaled a -&gt; a
</span><a href="GHC.Core.TyCo.Rep.html#scaledThing"><span class="hs-identifier hs-var">scaledThing</span></a></span><span> </span><span class="annot"><span class="annottext">Scaled Type
</span><a href="#local-6989586621680960517"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="annot"><span class="annottext">Type -&gt; Type -&gt; Bool
</span><a href="GHC.Core.Type.html#eqType"><span class="hs-operator hs-var">`eqType`</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="GHC.Builtin.Types.Prim.html#realWorldStatePrimTy"><span class="hs-identifier hs-var">realWorldStatePrimTy</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[(Scaled Type, StrictnessMark)]
</span><a href="#local-6989586621680960521"><span class="hs-identifier hs-var">field_tys</span></a></span><span>
</span><span id="line-369"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-370"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-371"></span><span>
</span><span id="line-372"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalAlt"><span class="hs-identifier hs-type">dmdAnalAlt</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#CleanDemand"><span class="hs-identifier hs-type">CleanDemand</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#Alt"><span class="hs-identifier hs-type">Alt</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#Alt"><span class="hs-identifier hs-type">Alt</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-373"></span><span id="dmdAnalAlt"><span class="annot"><span class="annottext">dmdAnalAlt :: AnalEnv -&gt; CleanDemand -&gt; Var -&gt; Alt Var -&gt; (DmdType, Alt Var)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalAlt"><span class="hs-identifier hs-var hs-var">dmdAnalAlt</span></a></span></span><span> </span><span id="local-6989586621680960515"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960515"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960514"><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960514"><span class="hs-identifier hs-var">dmd</span></a></span></span><span> </span><span id="local-6989586621680960513"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960513"><span class="hs-identifier hs-var">case_bndr</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680960512"><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680960512"><span class="hs-identifier hs-var">con</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680960511"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960511"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680960510"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960510"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-374"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">[Var] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960511"><span class="hs-identifier hs-var">bndrs</span></a></span><span>    </span><span class="hs-comment">-- Literals, DEFAULT, and nullary constructors</span><span>
</span><span id="line-375"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680960508"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960508"><span class="hs-identifier hs-var">rhs_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960507"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960507"><span class="hs-identifier hs-var">rhs'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal"><span class="hs-identifier hs-var">dmdAnal</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960515"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960514"><span class="hs-identifier hs-var">dmd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960510"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-376"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960508"><span class="hs-identifier hs-var">rhs_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680960512"><span class="hs-identifier hs-var">con</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960507"><span class="hs-identifier hs-var">rhs'</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-377"></span><span>
</span><span id="line-378"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>     </span><span class="hs-comment">-- Non-nullary data constructors</span><span>
</span><span id="line-379"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680960506"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960506"><span class="hs-identifier hs-var">rhs_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960505"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960505"><span class="hs-identifier hs-var">rhs'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal"><span class="hs-identifier hs-var">dmdAnal</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960515"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960514"><span class="hs-identifier hs-var">dmd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960510"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-380"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680960504"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960504"><span class="hs-identifier hs-var">alt_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960503"><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960503"><span class="hs-identifier hs-var">dmds</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; DmdType -&gt; [Var] -&gt; (DmdType, [Demand])
</span><a href="GHC.Core.Opt.DmdAnal.html#findBndrsDmds"><span class="hs-identifier hs-var">findBndrsDmds</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960515"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960506"><span class="hs-identifier hs-var">rhs_ty</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960511"><span class="hs-identifier hs-var">bndrs</span></a></span><span>
</span><span id="line-381"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680960502"><span class="annot"><span class="annottext">case_bndr_dmd :: Demand
</span><a href="#local-6989586621680960502"><span class="hs-identifier hs-var hs-var">case_bndr_dmd</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; Var -&gt; Demand
</span><a href="GHC.Types.Demand.html#findIdDemand"><span class="hs-identifier hs-var">findIdDemand</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960504"><span class="hs-identifier hs-var">alt_ty</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960513"><span class="hs-identifier hs-var">case_bndr</span></a></span><span>
</span><span id="line-382"></span><span>        </span><span id="local-6989586621680960500"><span class="annot"><span class="annottext">id_dmds :: [Demand]
</span><a href="#local-6989586621680960500"><span class="hs-identifier hs-var hs-var">id_dmds</span></a></span></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Demand -&gt; [Demand] -&gt; [Demand]
</span><a href="GHC.Types.Demand.html#addCaseBndrDmd"><span class="hs-identifier hs-var">addCaseBndrDmd</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960502"><span class="hs-identifier hs-var">case_bndr_dmd</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960503"><span class="hs-identifier hs-var">dmds</span></a></span><span>
</span><span id="line-383"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960504"><span class="hs-identifier hs-var">alt_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">AltCon
</span><a href="#local-6989586621680960512"><span class="hs-identifier hs-var">con</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Var] -&gt; [Demand] -&gt; [Var]
</span><a href="GHC.Core.Opt.DmdAnal.html#setBndrsDemandInfo"><span class="hs-identifier hs-var">setBndrsDemandInfo</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960511"><span class="hs-identifier hs-var">bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960500"><span class="hs-identifier hs-var">id_dmds</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960505"><span class="hs-identifier hs-var">rhs'</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-384"></span><span>
</span><span id="line-385"></span><span class="hs-comment">{- Note [Which scrutinees may throw precise exceptions]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is the specification of 'exprMayThrowPreciseExceptions',
which is important for Scenario 2 of
Note [Precise exceptions and strictness analysis] in GHC.Types.Demand.

For an expression @f a1 ... an :: ty@ we determine that
  1. False  If ty is *not* @State# RealWorld@ or an unboxed tuple thereof.
            This check is done by 'forcesRealWorld'.
            (Why not simply unboxed pairs as above? This is motivated by
            T13380{d,e}.)
  2. False  If f is a PrimOp, and it is *not* raiseIO#
  3. False  If f is an unsafe FFI call ('PlayRisky')
  _. True   Otherwise &quot;give up&quot;.

It is sound to return False in those cases, because
  1. We don't give any guarantees for unsafePerformIO, so no precise exceptions
     from pure code.
  2. raiseIO# is the only primop that may throw a precise exception.
  3. Unsafe FFI calls may not interact with the RTS (to throw, for example).
     See haddock on GHC.Types.ForeignCall.PlayRisky.

We *need* to return False in those cases, because
  1. We would lose too much strictness in pure code, all over the place.
  2. We would lose strictness for primops like getMaskingState#, which
     introduces a substantial regression in
     GHC.IO.Handle.Internals.wantReadableHandle.
  3. We would lose strictness for code like GHC.Fingerprint.fingerprintData,
     where an intermittent FFI call to c_MD5Init would otherwise lose
     strictness on the arguments len and buf, leading to regressions in T9203
     (2%) and i386's haddock.base (5%). Tested by T13380f.

In !3014 we tried a more sophisticated analysis by introducing ConOrDiv (nic)
to the Divergence lattice, but in practice it turned out to be hard to untaint
from 'topDiv' to 'conDiv', leading to bugs, performance regressions and
complexity that didn't justify the single fixed testcase T13380c.

Note [Demand on the scrutinee of a product case]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When figuring out the demand on the scrutinee of a product case,
we use the demands of the case alternative, i.e. id_dmds.
But note that these include the demand on the case binder;
see Note [Demand on case-alternative binders] in GHC.Types.Demand.
This is crucial. Example:
   f x = case x of y { (a,b) -&gt; k y a }
If we just take scrut_demand = U(L,A), then we won't pass x to the
worker, so the worker will rebuild
     x = (a, absent-error)
and that'll crash.

Note [Aggregated demand for cardinality]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We use different strategies for strictness and usage/cardinality to
&quot;unleash&quot; demands captured on free variables by bindings. Let us
consider the example:

f1 y = let {-# NOINLINE h #-}
           h = y
       in  (h, h)

We are interested in obtaining cardinality demand U1 on |y|, as it is
used only in a thunk, and, therefore, is not going to be updated any
more. Therefore, the demand on |y|, captured and unleashed by usage of
|h| is U1. However, if we unleash this demand every time |h| is used,
and then sum up the effects, the ultimate demand on |y| will be U1 +
U1 = U. In order to avoid it, we *first* collect the aggregate demand
on |h| in the body of let-expression, and only then apply the demand
transformer:

transf[x](U) = {y |-&gt; U1}

so the resulting demand on |y| is U1.

The situation is, however, different for strictness, where this
aggregating approach exhibits worse results because of the nature of
|both| operation for strictness. Consider the example:

f y c =
  let h x = y |seq| x
   in case of
        True  -&gt; h True
        False -&gt; y

It is clear that |f| is strict in |y|, however, the suggested analysis
will infer from the body of |let| that |h| is used lazily (as it is
used in one branch only), therefore lazy demand will be put on its
free variable |y|. Conversely, if the demand on |h| is unleashed right
on the spot, we will get the desired result, namely, that |f| is
strict in |y|.


************************************************************************
*                                                                      *
                    Demand transformer
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-482"></span><span>
</span><span id="line-483"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdTransform"><span class="hs-identifier hs-type">dmdTransform</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span>         </span><span class="hs-comment">-- The strictness environment</span><span>
</span><span id="line-484"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span>              </span><span class="hs-comment">-- The function</span><span>
</span><span id="line-485"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#CleanDemand"><span class="hs-identifier hs-type">CleanDemand</span></a></span><span>     </span><span class="hs-comment">-- The demand on the function</span><span>
</span><span id="line-486"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span>         </span><span class="hs-comment">-- The demand type of the function in this context</span><span>
</span><span id="line-487"></span><span>        </span><span class="hs-comment">-- Returned DmdEnv includes the demand on</span><span>
</span><span id="line-488"></span><span>        </span><span class="hs-comment">-- this function plus demand on its free variables</span><span>
</span><span id="line-489"></span><span>
</span><span id="line-490"></span><span id="dmdTransform"><span class="annot"><span class="annottext">dmdTransform :: AnalEnv -&gt; Var -&gt; CleanDemand -&gt; DmdType
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdTransform"><span class="hs-identifier hs-var hs-var">dmdTransform</span></a></span></span><span> </span><span id="local-6989586621680960499"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960499"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960498"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960498"><span class="hs-identifier hs-var">var</span></a></span></span><span> </span><span id="local-6989586621680960497"><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960497"><span class="hs-identifier hs-var">dmd</span></a></span></span><span>
</span><span id="line-491"></span><span>  </span><span class="hs-comment">-- Data constructors</span><span>
</span><span id="line-492"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Types.Id.html#isDataConWorkId"><span class="hs-identifier hs-var">isDataConWorkId</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960498"><span class="hs-identifier hs-var">var</span></a></span><span>
</span><span id="line-493"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity -&gt; CleanDemand -&gt; DmdType
</span><a href="GHC.Types.Demand.html#dmdTransformDataConSig"><span class="hs-identifier hs-var">dmdTransformDataConSig</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; Arity
</span><a href="GHC.Types.Id.html#idArity"><span class="hs-identifier hs-var">idArity</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960498"><span class="hs-identifier hs-var">var</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960497"><span class="hs-identifier hs-var">dmd</span></a></span><span>
</span><span id="line-494"></span><span>  </span><span class="hs-comment">-- Dictionary component selectors</span><span>
</span><span id="line-495"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">GeneralFlag -&gt; DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#gopt"><span class="hs-identifier hs-var">gopt</span></a></span><span> </span><span class="annot"><span class="annottext">GeneralFlag
</span><a href="GHC.Driver.Flags.html#Opt_DmdTxDictSel"><span class="hs-identifier hs-var">Opt_DmdTxDictSel</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">AnalEnv -&gt; DynFlags
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_dflags"><span class="hs-identifier hs-var hs-var">ae_dflags</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960499"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-496"></span><span>    </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Maybe Class
</span><a href="GHC.Types.Id.html#isClassOpId_maybe"><span class="hs-identifier hs-var">isClassOpId_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960498"><span class="hs-identifier hs-var">var</span></a></span><span>
</span><span id="line-497"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StrictSig -&gt; CleanDemand -&gt; DmdType
</span><a href="GHC.Types.Demand.html#dmdTransformDictSelSig"><span class="hs-identifier hs-var">dmdTransformDictSelSig</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; StrictSig
</span><a href="GHC.Types.Id.html#idStrictness"><span class="hs-identifier hs-var">idStrictness</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960498"><span class="hs-identifier hs-var">var</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960497"><span class="hs-identifier hs-var">dmd</span></a></span><span>
</span><span id="line-498"></span><span>  </span><span class="hs-comment">-- Imported functions</span><span>
</span><span id="line-499"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Types.Var.html#isGlobalId"><span class="hs-identifier hs-var">isGlobalId</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960498"><span class="hs-identifier hs-var">var</span></a></span><span>
</span><span id="line-500"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680960486"><span class="annot"><span class="annottext">res :: DmdType
</span><a href="#local-6989586621680960486"><span class="hs-identifier hs-var hs-var">res</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StrictSig -&gt; CleanDemand -&gt; DmdType
</span><a href="GHC.Types.Demand.html#dmdTransformSig"><span class="hs-identifier hs-var">dmdTransformSig</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; StrictSig
</span><a href="GHC.Types.Id.html#idStrictness"><span class="hs-identifier hs-var">idStrictness</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960498"><span class="hs-identifier hs-var">var</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960497"><span class="hs-identifier hs-var">dmd</span></a></span><span>
</span><span id="line-501"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-comment">-- pprTrace &quot;dmdTransform:import&quot; (vcat [ppr var, ppr (idStrictness var), ppr dmd, ppr res])</span><span>
</span><span id="line-502"></span><span>    </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960486"><span class="hs-identifier hs-var">res</span></a></span><span>
</span><span id="line-503"></span><span>  </span><span class="hs-comment">-- Top-level or local let-bound thing for which we use LetDown ('useLetUp').</span><span>
</span><span id="line-504"></span><span>  </span><span class="hs-comment">-- In that case, we have a strictness signature to unleash in our AnalEnv.</span><span>
</span><span id="line-505"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680960484"><span class="annot"><span class="annottext">StrictSig
</span><a href="#local-6989586621680960484"><span class="hs-identifier hs-var">sig</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960483"><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680960483"><span class="hs-identifier hs-var">top_lvl</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; Var -&gt; Maybe (StrictSig, TopLevelFlag)
</span><a href="GHC.Core.Opt.DmdAnal.html#lookupSigEnv"><span class="hs-identifier hs-var">lookupSigEnv</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960499"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960498"><span class="hs-identifier hs-var">var</span></a></span><span>
</span><span id="line-506"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680960481"><span class="annot"><span class="annottext">fn_ty :: DmdType
</span><a href="#local-6989586621680960481"><span class="hs-identifier hs-var hs-var">fn_ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">StrictSig -&gt; CleanDemand -&gt; DmdType
</span><a href="GHC.Types.Demand.html#dmdTransformSig"><span class="hs-identifier hs-var">dmdTransformSig</span></a></span><span> </span><span class="annot"><span class="annottext">StrictSig
</span><a href="#local-6989586621680960484"><span class="hs-identifier hs-var">sig</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960497"><span class="hs-identifier hs-var">dmd</span></a></span><span>
</span><span id="line-507"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-comment">-- pprTrace &quot;dmdTransform:LetDown&quot; (vcat [ppr var, ppr sig, ppr dmd, ppr fn_ty]) $</span><span>
</span><span id="line-508"></span><span>    </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">TopLevelFlag -&gt; Bool
</span><a href="GHC.Types.Basic.html#isTopLevel"><span class="hs-identifier hs-var">isTopLevel</span></a></span><span> </span><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680960483"><span class="hs-identifier hs-var">top_lvl</span></a></span><span>
</span><span id="line-509"></span><span>    </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960481"><span class="hs-identifier hs-var">fn_ty</span></a></span><span>   </span><span class="hs-comment">-- Don't record demand on top-level things</span><span>
</span><span id="line-510"></span><span>    </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; Var -&gt; Demand -&gt; DmdType
</span><a href="GHC.Core.Opt.DmdAnal.html#addVarDmd"><span class="hs-identifier hs-var">addVarDmd</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960481"><span class="hs-identifier hs-var">fn_ty</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960498"><span class="hs-identifier hs-var">var</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CleanDemand -&gt; Demand
</span><a href="GHC.Types.Demand.html#mkOnceUsedDmd"><span class="hs-identifier hs-var">mkOnceUsedDmd</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960497"><span class="hs-identifier hs-var">dmd</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-511"></span><span>  </span><span class="hs-comment">-- Everything else:</span><span>
</span><span id="line-512"></span><span>  </span><span class="hs-comment">--   * Local let binders for which we use LetUp (cf. 'useLetUp')</span><span>
</span><span id="line-513"></span><span>  </span><span class="hs-comment">--   * Lambda binders</span><span>
</span><span id="line-514"></span><span>  </span><span class="hs-comment">--   * Case and constructor field binders</span><span>
</span><span id="line-515"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-516"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-comment">-- pprTrace &quot;dmdTransform:other&quot; (vcat [ppr var, ppr sig, ppr dmd, ppr res]) $</span><span>
</span><span id="line-517"></span><span>    </span><span class="annot"><span class="annottext">DmdEnv -&gt; DmdType
</span><a href="GHC.Core.Opt.DmdAnal.html#unitDmdType"><span class="hs-identifier hs-var">unitDmdType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; Demand -&gt; DmdEnv
forall a. Var -&gt; a -&gt; VarEnv a
</span><a href="GHC.Types.Var.Env.html#unitVarEnv"><span class="hs-identifier hs-var">unitVarEnv</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960498"><span class="hs-identifier hs-var">var</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CleanDemand -&gt; Demand
</span><a href="GHC.Types.Demand.html#mkOnceUsedDmd"><span class="hs-identifier hs-var">mkOnceUsedDmd</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960497"><span class="hs-identifier hs-var">dmd</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-518"></span><span>
</span><span id="line-519"></span><span class="hs-comment">{- *********************************************************************
*                                                                      *
                      Binding right-hand sides
*                                                                      *
********************************************************************* -}</span><span>
</span><span id="line-524"></span><span>
</span><span id="line-525"></span><span class="hs-comment">-- Let bindings can be processed in two ways:</span><span>
</span><span id="line-526"></span><span class="hs-comment">-- Down (RHS before body) or Up (body before RHS).</span><span>
</span><span id="line-527"></span><span class="hs-comment">-- dmdAnalRhsLetDown implements the Down variant:</span><span>
</span><span id="line-528"></span><span class="hs-comment">--  * assuming a demand of &lt;L,U&gt;</span><span>
</span><span id="line-529"></span><span class="hs-comment">--  * looking at the definition</span><span>
</span><span id="line-530"></span><span class="hs-comment">--  * determining a strictness signature</span><span>
</span><span id="line-531"></span><span class="hs-comment">--</span><span>
</span><span id="line-532"></span><span class="hs-comment">-- It is used for toplevel definition, recursive definitions and local</span><span>
</span><span id="line-533"></span><span class="hs-comment">-- non-recursive definitions that have manifest lambdas.</span><span>
</span><span id="line-534"></span><span class="hs-comment">-- Local non-recursive definitions without a lambda are handled with LetUp.</span><span>
</span><span id="line-535"></span><span class="hs-comment">--</span><span>
</span><span id="line-536"></span><span class="hs-comment">-- This is the LetDown rule in the paper &#8220;Higher-Order Cardinality Analysis&#8221;.</span><span>
</span><span id="line-537"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalRhsLetDown"><span class="hs-identifier hs-type">dmdAnalRhsLetDown</span></a></span><span>
</span><span id="line-538"></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">]</span><span>   </span><span class="hs-comment">-- Just bs &lt;=&gt; recursive, Nothing &lt;=&gt; non-recursive</span><span>
</span><span id="line-539"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#CleanDemand"><span class="hs-identifier hs-type">CleanDemand</span></a></span><span>
</span><span id="line-540"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span>
</span><span id="line-541"></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Demand.html#DmdEnv"><span class="hs-identifier hs-type">DmdEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#StrictSig"><span class="hs-identifier hs-type">StrictSig</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-542"></span><span class="hs-comment">-- Process the RHS of the binding, add the strictness signature</span><span>
</span><span id="line-543"></span><span class="hs-comment">-- to the Id, and augment the environment with the signature as well.</span><span>
</span><span id="line-544"></span><span class="hs-comment">-- See Note [NOINLINE and strictness]</span><span>
</span><span id="line-545"></span><span id="dmdAnalRhsLetDown"><span class="annot"><span class="annottext">dmdAnalRhsLetDown :: Maybe [Var]
-&gt; AnalEnv
-&gt; CleanDemand
-&gt; Var
-&gt; CoreExpr
-&gt; (DmdEnv, StrictSig, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalRhsLetDown"><span class="hs-identifier hs-var hs-var">dmdAnalRhsLetDown</span></a></span></span><span> </span><span id="local-6989586621680960476"><span class="annot"><span class="annottext">Maybe [Var]
</span><a href="#local-6989586621680960476"><span class="hs-identifier hs-var">rec_flag</span></a></span></span><span> </span><span id="local-6989586621680960475"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960475"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960474"><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960474"><span class="hs-identifier hs-var">let_dmd</span></a></span></span><span> </span><span id="local-6989586621680960473"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960473"><span class="hs-identifier hs-var">id</span></a></span></span><span> </span><span id="local-6989586621680960472"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960472"><span class="hs-identifier hs-var">rhs</span></a></span></span><span>
</span><span id="line-546"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960471"><span class="hs-identifier hs-var">lazy_fv</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">StrictSig
</span><a href="#local-6989586621680960470"><span class="hs-identifier hs-var">sig</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960469"><span class="hs-identifier hs-var">rhs'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-547"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-548"></span><span>    </span><span id="local-6989586621680960468"><span class="annot"><span class="annottext">rhs_arity :: Arity
</span><a href="#local-6989586621680960468"><span class="hs-identifier hs-var hs-var">rhs_arity</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Arity
</span><a href="GHC.Types.Id.html#idArity"><span class="hs-identifier hs-var">idArity</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960473"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-549"></span><span>    </span><span id="local-6989586621680960467"><span class="annot"><span class="annottext">rhs_dmd :: CleanDemand
</span><a href="#local-6989586621680960467"><span class="hs-identifier hs-var hs-var">rhs_dmd</span></a></span></span><span> </span><span class="hs-comment">-- See Note [Demand analysis for join points]</span><span>
</span><span id="line-550"></span><span>            </span><span class="hs-comment">-- See Note [Invariants on join points] invariant 2b, in GHC.Core</span><span>
</span><span id="line-551"></span><span>            </span><span class="hs-comment">--     rhs_arity matches the join arity of the join point</span><span>
</span><span id="line-552"></span><span>            </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Types.Id.html#isJoinId"><span class="hs-identifier hs-var">isJoinId</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960473"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-553"></span><span>            </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity -&gt; CleanDemand -&gt; CleanDemand
</span><a href="GHC.Types.Demand.html#mkCallDmds"><span class="hs-identifier hs-var">mkCallDmds</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680960468"><span class="hs-identifier hs-var">rhs_arity</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960474"><span class="hs-identifier hs-var">let_dmd</span></a></span><span>
</span><span id="line-554"></span><span>            </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-555"></span><span>            </span><span class="hs-comment">-- NB: rhs_arity</span><span>
</span><span id="line-556"></span><span>            </span><span class="hs-comment">-- See Note [Demand signatures are computed for a threshold demand based on idArity]</span><span>
</span><span id="line-557"></span><span>            </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; Arity -&gt; CoreExpr -&gt; CleanDemand
</span><a href="GHC.Core.Opt.DmdAnal.html#mkRhsDmd"><span class="hs-identifier hs-var">mkRhsDmd</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960475"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680960468"><span class="hs-identifier hs-var">rhs_arity</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960472"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-558"></span><span>
</span><span id="line-559"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680960463"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960463"><span class="hs-identifier hs-var">rhs_dmd_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960469"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960469"><span class="hs-identifier hs-var">rhs'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; CleanDemand -&gt; CoreExpr -&gt; (DmdType, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnal"><span class="hs-identifier hs-var">dmdAnal</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960475"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960467"><span class="hs-identifier hs-var">rhs_dmd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960472"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-560"></span><span>    </span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span> </span><span id="local-6989586621680960462"><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960462"><span class="hs-identifier hs-var">rhs_fv</span></a></span></span><span> </span><span id="local-6989586621680960461"><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960461"><span class="hs-identifier hs-var">rhs_dmds</span></a></span></span><span> </span><span id="local-6989586621680960460"><span class="annot"><span class="annottext">Divergence
</span><a href="#local-6989586621680960460"><span class="hs-identifier hs-var">rhs_div</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960463"><span class="hs-identifier hs-var">rhs_dmd_ty</span></a></span><span>
</span><span id="line-561"></span><span>
</span><span id="line-562"></span><span>    </span><span id="local-6989586621680960470"><span class="annot"><span class="annottext">sig :: StrictSig
</span><a href="#local-6989586621680960470"><span class="hs-identifier hs-var hs-var">sig</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity -&gt; DmdType -&gt; StrictSig
</span><a href="GHC.Types.Demand.html#mkStrictSigForArity"><span class="hs-identifier hs-var">mkStrictSigForArity</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680960468"><span class="hs-identifier hs-var">rhs_arity</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdEnv -&gt; [Demand] -&gt; Divergence -&gt; DmdType
</span><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-var">DmdType</span></a></span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960458"><span class="hs-identifier hs-var">sig_fv</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960461"><span class="hs-identifier hs-var">rhs_dmds</span></a></span><span> </span><span class="annot"><span class="annottext">Divergence
</span><a href="#local-6989586621680960460"><span class="hs-identifier hs-var">rhs_div</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-563"></span><span>
</span><span id="line-564"></span><span>    </span><span class="hs-comment">-- See Note [Aggregated demand for cardinality]</span><span>
</span><span id="line-565"></span><span>    </span><span id="local-6989586621680960457"><span class="annot"><span class="annottext">rhs_fv1 :: DmdEnv
</span><a href="#local-6989586621680960457"><span class="hs-identifier hs-var hs-var">rhs_fv1</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe [Var]
</span><a href="#local-6989586621680960476"><span class="hs-identifier hs-var">rec_flag</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-566"></span><span>                </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680960456"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960456"><span class="hs-identifier hs-var">bs</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DmdEnv -&gt; DmdEnv
</span><a href="GHC.Types.Demand.html#reuseEnv"><span class="hs-identifier hs-var">reuseEnv</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdEnv -&gt; [Var] -&gt; DmdEnv
forall a. VarEnv a -&gt; [Var] -&gt; VarEnv a
</span><a href="GHC.Types.Var.Env.html#delVarEnvList"><span class="hs-identifier hs-var">delVarEnvList</span></a></span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960462"><span class="hs-identifier hs-var">rhs_fv</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960456"><span class="hs-identifier hs-var">bs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-567"></span><span>                </span><span class="annot"><span class="annottext">Maybe [Var]
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960462"><span class="hs-identifier hs-var">rhs_fv</span></a></span><span>
</span><span id="line-568"></span><span>
</span><span id="line-569"></span><span>    </span><span id="local-6989586621680960454"><span class="annot"><span class="annottext">rhs_fv2 :: DmdEnv
</span><a href="#local-6989586621680960454"><span class="hs-identifier hs-var hs-var">rhs_fv2</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960457"><span class="hs-identifier hs-var">rhs_fv1</span></a></span><span> </span><span class="annot"><span class="annottext">DmdEnv -&gt; IdSet -&gt; DmdEnv
</span><a href="GHC.Types.Demand.html#keepAliveDmdEnv"><span class="hs-operator hs-var">`keepAliveDmdEnv`</span></a></span><span> </span><span class="annot"><span class="annottext">IdSet
</span><a href="#local-6989586621680960452"><span class="hs-identifier hs-var">extra_fvs</span></a></span><span>
</span><span id="line-570"></span><span>
</span><span id="line-571"></span><span>    </span><span class="hs-comment">-- See Note [Lazy and unleashable free variables]</span><span>
</span><span id="line-572"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680960471"><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960471"><span class="hs-identifier hs-var">lazy_fv</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960458"><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960458"><span class="hs-identifier hs-var">sig_fv</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; DmdEnv -&gt; (DmdEnv, DmdEnv)
</span><a href="GHC.Types.Demand.html#splitFVs"><span class="hs-identifier hs-var">splitFVs</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680960450"><span class="hs-identifier hs-var">is_thunk</span></a></span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960454"><span class="hs-identifier hs-var">rhs_fv2</span></a></span><span>
</span><span id="line-573"></span><span>    </span><span id="local-6989586621680960450"><span class="annot"><span class="annottext">is_thunk :: Bool
</span><a href="#local-6989586621680960450"><span class="hs-identifier hs-var hs-var">is_thunk</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CoreExpr -&gt; Bool
</span><a href="GHC.Core.Utils.html#exprIsHNF"><span class="hs-identifier hs-var">exprIsHNF</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960472"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Types.Id.html#isJoinId"><span class="hs-identifier hs-var">isJoinId</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960473"><span class="hs-identifier hs-var">id</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-574"></span><span>
</span><span id="line-575"></span><span>    </span><span class="hs-comment">-- Find the RHS free vars of the unfoldings and RULES</span><span>
</span><span id="line-576"></span><span>    </span><span class="hs-comment">-- See Note [Absence analysis for stable unfoldings and RULES]</span><span>
</span><span id="line-577"></span><span>    </span><span id="local-6989586621680960452"><span class="annot"><span class="annottext">extra_fvs :: IdSet
</span><a href="#local-6989586621680960452"><span class="hs-identifier hs-var hs-var">extra_fvs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(CoreRule -&gt; IdSet -&gt; IdSet) -&gt; IdSet -&gt; [CoreRule] -&gt; IdSet
forall (t :: * -&gt; *) a b.
Foldable t =&gt;
(a -&gt; b -&gt; b) -&gt; b -&gt; t a -&gt; b
</span><a href="../../base/src/Data.Foldable.html#foldr"><span class="hs-identifier hs-var">foldr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IdSet -&gt; IdSet -&gt; IdSet
</span><a href="GHC.Types.Var.Set.html#unionVarSet"><span class="hs-identifier hs-var">unionVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">(IdSet -&gt; IdSet -&gt; IdSet)
-&gt; (CoreRule -&gt; IdSet) -&gt; CoreRule -&gt; IdSet -&gt; IdSet
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">CoreRule -&gt; IdSet
</span><a href="GHC.Core.FVs.html#ruleRhsFreeIds"><span class="hs-identifier hs-var">ruleRhsFreeIds</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">IdSet
</span><a href="#local-6989586621680960446"><span class="hs-identifier hs-var">unf_fvs</span></a></span><span> </span><span class="annot"><span class="annottext">([CoreRule] -&gt; IdSet) -&gt; [CoreRule] -&gt; IdSet
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-578"></span><span>                </span><span class="annot"><span class="annottext">Var -&gt; [CoreRule]
</span><a href="GHC.Types.Id.html#idCoreRules"><span class="hs-identifier hs-var">idCoreRules</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960473"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-579"></span><span>
</span><span id="line-580"></span><span>    </span><span id="local-6989586621680960444"><span class="annot"><span class="annottext">unf :: Unfolding
</span><a href="#local-6989586621680960444"><span class="hs-identifier hs-var hs-var">unf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Unfolding
</span><a href="GHC.Types.Id.html#realIdUnfolding"><span class="hs-identifier hs-var">realIdUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960473"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-581"></span><span>    </span><span id="local-6989586621680960446"><span class="annot"><span class="annottext">unf_fvs :: IdSet
</span><a href="#local-6989586621680960446"><span class="hs-identifier hs-var hs-var">unf_fvs</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Unfolding -&gt; Bool
</span><a href="GHC.Core.html#isStableUnfolding"><span class="hs-identifier hs-var">isStableUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">Unfolding
</span><a href="#local-6989586621680960444"><span class="hs-identifier hs-var">unf</span></a></span><span>
</span><span id="line-582"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680960441"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960441"><span class="hs-identifier hs-var">unf_body</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Unfolding -&gt; Maybe CoreExpr
</span><a href="GHC.Core.html#maybeUnfoldingTemplate"><span class="hs-identifier hs-var">maybeUnfoldingTemplate</span></a></span><span> </span><span class="annot"><span class="annottext">Unfolding
</span><a href="#local-6989586621680960444"><span class="hs-identifier hs-var">unf</span></a></span><span>
</span><span id="line-583"></span><span>            </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">CoreExpr -&gt; IdSet
</span><a href="GHC.Core.FVs.html#exprFreeIds"><span class="hs-identifier hs-var">exprFreeIds</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960441"><span class="hs-identifier hs-var">unf_body</span></a></span><span>
</span><span id="line-584"></span><span>            </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IdSet
</span><a href="GHC.Types.Var.Set.html#emptyVarSet"><span class="hs-identifier hs-var">emptyVarSet</span></a></span><span>
</span><span id="line-585"></span><span>
</span><span id="line-586"></span><span class="hs-comment">-- | @mkRhsDmd env rhs_arity rhs@ creates a 'CleanDemand' for</span><span>
</span><span id="line-587"></span><span class="hs-comment">-- unleashing on the given function's @rhs@, by creating</span><span>
</span><span id="line-588"></span><span class="hs-comment">-- a call demand of @rhs_arity@</span><span>
</span><span id="line-589"></span><span class="hs-comment">-- See Historical Note [Product demands for function body]</span><span>
</span><span id="line-590"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#mkRhsDmd"><span class="hs-identifier hs-type">mkRhsDmd</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#Arity"><span class="hs-identifier hs-type">Arity</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#CleanDemand"><span class="hs-identifier hs-type">CleanDemand</span></a></span><span>
</span><span id="line-591"></span><span id="mkRhsDmd"><span class="annot"><span class="annottext">mkRhsDmd :: AnalEnv -&gt; Arity -&gt; CoreExpr -&gt; CleanDemand
</span><a href="GHC.Core.Opt.DmdAnal.html#mkRhsDmd"><span class="hs-identifier hs-var hs-var">mkRhsDmd</span></a></span></span><span> </span><span id="local-6989586621680960438"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960438"><span class="hs-identifier hs-var">_env</span></a></span></span><span> </span><span id="local-6989586621680960437"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680960437"><span class="hs-identifier hs-var">rhs_arity</span></a></span></span><span> </span><span id="local-6989586621680960436"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960436"><span class="hs-identifier hs-var">_rhs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity -&gt; CleanDemand -&gt; CleanDemand
</span><a href="GHC.Types.Demand.html#mkCallDmds"><span class="hs-identifier hs-var">mkCallDmds</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680960437"><span class="hs-identifier hs-var">rhs_arity</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="GHC.Types.Demand.html#cleanEvalDmd"><span class="hs-identifier hs-var">cleanEvalDmd</span></a></span><span>
</span><span id="line-592"></span><span>
</span><span id="line-593"></span><span class="hs-comment">-- | If given the let-bound 'Id', 'useLetUp' determines whether we should</span><span>
</span><span id="line-594"></span><span class="hs-comment">-- process the binding up (body before rhs) or down (rhs before body).</span><span>
</span><span id="line-595"></span><span class="hs-comment">--</span><span>
</span><span id="line-596"></span><span class="hs-comment">-- We use LetDown if there is a chance to get a useful strictness signature to</span><span>
</span><span id="line-597"></span><span class="hs-comment">-- unleash at call sites. LetDown is generally more precise than LetUp if we can</span><span>
</span><span id="line-598"></span><span class="hs-comment">-- correctly guess how it will be used in the body, that is, for which incoming</span><span>
</span><span id="line-599"></span><span class="hs-comment">-- demand the strictness signature should be computed, which allows us to</span><span>
</span><span id="line-600"></span><span class="hs-comment">-- unleash higher-order demands on arguments at call sites. This is mostly the</span><span>
</span><span id="line-601"></span><span class="hs-comment">-- case when</span><span>
</span><span id="line-602"></span><span class="hs-comment">--</span><span>
</span><span id="line-603"></span><span class="hs-comment">--   * The binding takes any arguments before performing meaningful work (cf.</span><span>
</span><span id="line-604"></span><span class="hs-comment">--     'idArity'), in which case we are interested to see how it uses them.</span><span>
</span><span id="line-605"></span><span class="hs-comment">--   * The binding is a join point, hence acting like a function, not a value.</span><span>
</span><span id="line-606"></span><span class="hs-comment">--     As a big plus, we know *precisely* how it will be used in the body; since</span><span>
</span><span id="line-607"></span><span class="hs-comment">--     it's always tail-called, we can directly unleash the incoming demand of</span><span>
</span><span id="line-608"></span><span class="hs-comment">--     the let binding on its RHS when computing a strictness signature. See</span><span>
</span><span id="line-609"></span><span class="hs-comment">--     [Demand analysis for join points].</span><span>
</span><span id="line-610"></span><span class="hs-comment">--</span><span>
</span><span id="line-611"></span><span class="hs-comment">-- Thus, if the binding is not a join point and its arity is 0, we have a thunk</span><span>
</span><span id="line-612"></span><span class="hs-comment">-- and use LetUp, implying that we have no usable demand signature available</span><span>
</span><span id="line-613"></span><span class="hs-comment">-- when we analyse the let body.</span><span>
</span><span id="line-614"></span><span class="hs-comment">--</span><span>
</span><span id="line-615"></span><span class="hs-comment">-- Since thunk evaluation is memoised, we want to unleash its 'DmdEnv' of free</span><span>
</span><span id="line-616"></span><span class="hs-comment">-- vars at most once, regardless of how many times it was forced in the body.</span><span>
</span><span id="line-617"></span><span class="hs-comment">-- This makes a real difference wrt. usage demands. The other reason is being</span><span>
</span><span id="line-618"></span><span class="hs-comment">-- able to unleash a more precise product demand on its RHS once we know how the</span><span>
</span><span id="line-619"></span><span class="hs-comment">-- thunk was used in the let body.</span><span>
</span><span id="line-620"></span><span class="hs-comment">--</span><span>
</span><span id="line-621"></span><span class="hs-comment">-- Characteristic examples, always assuming a single evaluation:</span><span>
</span><span id="line-622"></span><span class="hs-comment">--</span><span>
</span><span id="line-623"></span><span class="hs-comment">--   * @let x = 2*y in x + x@ =&gt; LetUp. Compared to LetDown, we find out that</span><span>
</span><span id="line-624"></span><span class="hs-comment">--     the expression uses @y@ at most once.</span><span>
</span><span id="line-625"></span><span class="hs-comment">--   * @let x = (a,b) in fst x@ =&gt; LetUp. Compared to LetDown, we find out that</span><span>
</span><span id="line-626"></span><span class="hs-comment">--     @b@ is absent.</span><span>
</span><span id="line-627"></span><span class="hs-comment">--   * @let f x = x*2 in f y@ =&gt; LetDown. Compared to LetUp, we find out that</span><span>
</span><span id="line-628"></span><span class="hs-comment">--     the expression uses @y@ strictly, because we have @f@'s demand signature</span><span>
</span><span id="line-629"></span><span class="hs-comment">--     available at the call site.</span><span>
</span><span id="line-630"></span><span class="hs-comment">--   * @join exit = 2*y in if a then exit else if b then exit else 3*y@ =&gt;</span><span>
</span><span id="line-631"></span><span class="hs-comment">--     LetDown. Compared to LetUp, we find out that the expression uses @y@</span><span>
</span><span id="line-632"></span><span class="hs-comment">--     strictly, because we can unleash @exit@'s signature at each call site.</span><span>
</span><span id="line-633"></span><span class="hs-comment">--   * For a more convincing example with join points, see Note [Demand analysis</span><span>
</span><span id="line-634"></span><span class="hs-comment">--     for join points].</span><span>
</span><span id="line-635"></span><span class="hs-comment">--</span><span>
</span><span id="line-636"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#useLetUp"><span class="hs-identifier hs-type">useLetUp</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-637"></span><span id="useLetUp"><span class="annot"><span class="annottext">useLetUp :: Var -&gt; Bool
</span><a href="GHC.Core.Opt.DmdAnal.html#useLetUp"><span class="hs-identifier hs-var hs-var">useLetUp</span></a></span></span><span> </span><span id="local-6989586621680960435"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960435"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Arity
</span><a href="GHC.Types.Id.html#idArity"><span class="hs-identifier hs-var">idArity</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960435"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Types.Id.html#isJoinId"><span class="hs-identifier hs-var">isJoinId</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960435"><span class="hs-identifier hs-var">f</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-638"></span><span>
</span><span id="line-639"></span><span class="hs-comment">{- Note [Demand analysis for join points]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider
   g :: (Int,Int) -&gt; Int
   g (p,q) = p+q

   f :: T -&gt; Int -&gt; Int
   f x p = g (join j y = (p,y)
              in case x of
                   A -&gt; j 3
                   B -&gt; j 4
                   C -&gt; (p,7))

If j was a vanilla function definition, we'd analyse its body with
evalDmd, and think that it was lazy in p.  But for join points we can
do better!  We know that j's body will (if called at all) be evaluated
with the demand that consumes the entire join-binding, in this case
the argument demand from g.  Whizzo!  g evaluates both components of
its argument pair, so p will certainly be evaluated if j is called.

For f to be strict in p, we need /all/ paths to evaluate p; in this
case the C branch does so too, so we are fine.  So, as usual, we need
to transport demands on free variables to the call site(s).  Compare
Note [Lazy and unleashable free variables].

The implementation is easy.  When analysing a join point, we can
analyse its body with the demand from the entire join-binding (written
let_dmd here).

Another win for join points!  #13543.

However, note that the strictness signature for a join point can
look a little puzzling.  E.g.

    (join j x = \y. error &quot;urk&quot;)
    (in case v of              )
    (     A -&gt; j 3             )  x
    (     B -&gt; j 4             )
    (     C -&gt; \y. blah        )

The entire thing is in a C(S) context, so j's strictness signature
will be    [A]b
meaning one absent argument, returns bottom.  That seems odd because
there's a \y inside.  But it's right because when consumed in a C(1)
context the RHS of the join point is indeed bottom.

Note [Demand signatures are computed for a threshold demand based on idArity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We compute demand signatures assuming idArity incoming arguments to approximate
behavior for when we have a call site with at least that many arguments. idArity
is /at least/ the number of manifest lambdas, but might be higher for PAPs and
trivial RHS (see Note [Demand analysis for trivial right-hand sides]).

Because idArity of a function varies independently of its cardinality properties
(cf. Note [idArity varies independently of dmdTypeDepth]), we implicitly encode
the arity for when a demand signature is sound to unleash in its 'dmdTypeDepth'
(cf. Note [Understanding DmdType and StrictSig] in GHC.Types.Demand). It is unsound to
unleash a demand signature when the incoming number of arguments is less than
that. See Note [What are demand signatures?] for more details on soundness.

Why idArity arguments? Because that's a conservative estimate of how many
arguments we must feed a function before it does anything interesting with them.
Also it elegantly subsumes the trivial RHS and PAP case.

There might be functions for which we might want to analyse for more incoming
arguments than idArity. Example:

  f x =
    if expensive
      then \y -&gt; ... y ...
      else \y -&gt; ... y ...

We'd analyse `f` under a unary call demand C(S), corresponding to idArity
being 1. That's enough to look under the manifest lambda and find out how a
unary call would use `x`, but not enough to look into the lambdas in the if
branches.

On the other hand, if we analysed for call demand C(C(S)), we'd get useful
strictness info for `y` (and more precise info on `x`) and possibly CPR
information, but

  * We would no longer be able to unleash the signature at unary call sites
  * Performing the worker/wrapper split based on this information would be
    implicitly eta-expanding `f`, playing fast and loose with divergence and
    even being unsound in the presence of newtypes, so we refrain from doing so.
    Also see Note [Don't eta expand in w/w] in GHC.Core.Opt.WorkWrap.

Since we only compute one signature, we do so for arity 1. Computing multiple
signatures for different arities (i.e., polyvariance) would be entirely
possible, if it weren't for the additional runtime and implementation
complexity.

Note [idArity varies independently of dmdTypeDepth]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We used to check in GHC.Core.Lint that dmdTypeDepth &lt;= idArity for a let-bound
identifier. But that means we would have to zap demand signatures every time we
reset or decrease arity. That's an unnecessary dependency, because

  * The demand signature captures a semantic property that is independent of
    what the binding's current arity is
  * idArity is analysis information itself, thus volatile
  * We already *have* dmdTypeDepth, wo why not just use it to encode the
    threshold for when to unleash the signature
    (cf. Note [Understanding DmdType and StrictSig] in GHC.Types.Demand)

Consider the following expression, for example:

    (let go x y = `x` seq ... in go) |&gt; co

`go` might have a strictness signature of `&lt;S&gt;&lt;L&gt;`. The simplifier will identify
`go` as a nullary join point through `joinPointBinding_maybe` and float the
coercion into the binding, leading to an arity decrease:

    join go = (\x y -&gt; `x` seq ...) |&gt; co in go

With the CoreLint check, we would have to zap `go`'s perfectly viable strictness
signature.

Note [What are demand signatures?]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demand analysis interprets expressions in the abstract domain of demand
transformers. Given an incoming demand we put an expression under, its abstract
transformer gives us back a demand type denoting how other things (like
arguments and free vars) were used when the expression was evaluated.
Here's an example:

  f x y =
    if x + expensive
      then \z -&gt; z + y * ...
      else \z -&gt; z * ...

The abstract transformer (let's call it F_e) of the if expression (let's call it
e) would transform an incoming head demand &lt;S,HU&gt; into a demand type like
{x-&gt;&lt;S,1*U&gt;,y-&gt;&lt;L,U&gt;}&lt;L,U&gt;. In pictures:

     Demand ---F_e---&gt; DmdType
     &lt;S,HU&gt;            {x-&gt;&lt;S,1*U&gt;,y-&gt;&lt;L,U&gt;}&lt;L,U&gt;

Let's assume that the demand transformers we compute for an expression are
correct wrt. to some concrete semantics for Core. How do demand signatures fit
in? They are strange beasts, given that they come with strict rules when to
it's sound to unleash them.

Fortunately, we can formalise the rules with Galois connections. Consider
f's strictness signature, {}&lt;S,1*U&gt;&lt;L,U&gt;. It's a single-point approximation of
the actual abstract transformer of f's RHS for arity 2. So, what happens is that
we abstract *once more* from the abstract domain we already are in, replacing
the incoming Demand by a simple lattice with two elements denoting incoming
arity: A_2 = {&lt;2, &gt;=2} (where '&lt;2' is the top element and &gt;=2 the bottom
element). Here's the diagram:

     A_2 -----f_f----&gt; DmdType
      ^                   |
      | &#945;               &#947; |
      |                   v
     Demand ---F_f---&gt; DmdType

With
  &#945;(C1(C1(_))) = &gt;=2 -- example for usage demands, but similar for strictness
  &#945;(_)         =  &lt;2
  &#947;(ty)        =  ty
and F_f being the abstract transformer of f's RHS and f_f being the abstracted
abstract transformer computable from our demand signature simply by

  f_f(&gt;=2) = {}&lt;S,1*U&gt;&lt;L,U&gt;
  f_f(&lt;2)  = postProcessUnsat {}&lt;S,1*U&gt;&lt;L,U&gt;

where postProcessUnsat makes a proper top element out of the given demand type.

Note [Demand analysis for trivial right-hand sides]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider
    foo = plusInt |&gt; co
where plusInt is an arity-2 function with known strictness.  Clearly
we want plusInt's strictness to propagate to foo!  But because it has
no manifest lambdas, it won't do so automatically, and indeed 'co' might
have type (Int-&gt;Int-&gt;Int) ~ T.

Fortunately, GHC.Core.Opt.Arity gives 'foo' arity 2, which is enough for LetDown to
forward plusInt's demand signature, and all is well (see Note [Newtype arity] in
GHC.Core.Opt.Arity)! A small example is the test case NewtypeArity.

Note [Absence analysis for stable unfoldings and RULES]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ticket #18638 shows that it's really important to do absence analysis
for stable unfoldings. Consider

   g = blah

   f = \x.  ...no use of g....
   {- f's stable unfolding is f = \x. ...g... -}

If f is ever inlined we use 'g'. But f's current RHS makes no use
of 'g', so if we don't look at the unfolding we'll mark g as Absent,
and transform to

   g = error &quot;Entered absent value&quot;
   f = \x. ...
   {- f's stable unfolding is f = \x. ...g... -}

Now if f is subsequently inlined, we'll use 'g' and ... disaster.

SOLUTION: if f has a stable unfolding, adjust its DmdEnv (the demands
on its free variables) so that no variable mentioned in its unfolding
is Absent.  This is done by the function Demand.keepAliveDmdEnv.

ALSO: do the same for Ids free in the RHS of any RULES for f.

PS: You may wonder how it can be that f's optimised RHS has somehow
discarded 'g', but when f is inlined we /don't/ discard g in the same
way. I think a simple example is
   g = (a,b)
   f = \x.  fst g
   {-# INLINE f #-}

Now f's optimised RHS will be \x.a, but if we change g to (error &quot;..&quot;)
(since it is apparently Absent) and then inline (\x. fst g) we get
disaster.  But regardless, #18638 was a more complicated version of
this, that actually happened in practice.

Historical Note [Product demands for function body]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In 2013 I spotted this example, in shootout/binary_trees:

    Main.check' = \ b z ds. case z of z' { I# ip -&gt;
                                case ds_d13s of
                                  Main.Nil -&gt; z'
                                  Main.Node s14k s14l s14m -&gt;
                                    Main.check' (not b)
                                      (Main.check' b
                                         (case b {
                                            False -&gt; I# (-# s14h s14k);
                                            True  -&gt; I# (+# s14h s14k)
                                          })
                                         s14l)
                                     s14m   }   }   }

Here we *really* want to unbox z, even though it appears to be used boxed in
the Nil case.  Partly the Nil case is not a hot path.  But more specifically,
the whole function gets the CPR property if we do.

That motivated using a demand of C(C(C(S(L,L)))) for the RHS, where
(solely because the result was a product) we used a product demand
(albeit with lazy components) for the body. But that gives very silly
behaviour -- see #17932.   Happily it turns out now to be entirely
unnecessary: we get good results with C(C(C(S))).   So I simply
deleted the special case.
-}</span><span>
</span><span id="line-887"></span><span>
</span><span id="line-888"></span><span class="hs-comment">{- *********************************************************************
*                                                                      *
                      Fixpoints
*                                                                      *
********************************************************************* -}</span><span>
</span><span id="line-893"></span><span>
</span><span id="line-894"></span><span class="hs-comment">-- Recursive bindings</span><span>
</span><span id="line-895"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#dmdFix"><span class="hs-identifier hs-type">dmdFix</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#TopLevelFlag"><span class="hs-identifier hs-type">TopLevelFlag</span></a></span><span>
</span><span id="line-896"></span><span>       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span>                            </span><span class="hs-comment">-- Does not include bindings for this binding</span><span>
</span><span id="line-897"></span><span>       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#CleanDemand"><span class="hs-identifier hs-type">CleanDemand</span></a></span><span>
</span><span id="line-898"></span><span>       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-899"></span><span>       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#DmdEnv"><span class="hs-identifier hs-type">DmdEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- Binders annotated with strictness info</span><span>
</span><span id="line-900"></span><span>
</span><span id="line-901"></span><span id="dmdFix"><span class="annot"><span class="annottext">dmdFix :: TopLevelFlag
-&gt; AnalEnv
-&gt; CleanDemand
-&gt; [(Var, CoreExpr)]
-&gt; (AnalEnv, DmdEnv, [(Var, CoreExpr)])
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdFix"><span class="hs-identifier hs-var hs-var">dmdFix</span></a></span></span><span> </span><span id="local-6989586621680960434"><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680960434"><span class="hs-identifier hs-var">top_lvl</span></a></span></span><span> </span><span id="local-6989586621680960433"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960433"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960432"><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960432"><span class="hs-identifier hs-var">let_dmd</span></a></span></span><span> </span><span id="local-6989586621680960431"><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960431"><span class="hs-identifier hs-var">orig_pairs</span></a></span></span><span>
</span><span id="line-902"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity -&gt; [(Var, CoreExpr)] -&gt; (AnalEnv, DmdEnv, [(Var, CoreExpr)])
</span><a href="#local-6989586621680960430"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960429"><span class="hs-identifier hs-var">initial_pairs</span></a></span><span>
</span><span id="line-903"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-904"></span><span>    </span><span id="local-6989586621680960428"><span class="annot"><span class="annottext">bndrs :: [Var]
</span><a href="#local-6989586621680960428"><span class="hs-identifier hs-var hs-var">bndrs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">((Var, CoreExpr) -&gt; Var) -&gt; [(Var, CoreExpr)] -&gt; [Var]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">(Var, CoreExpr) -&gt; Var
forall a b. (a, b) -&gt; a
</span><a href="../../base/src/Data.Tuple.html#fst"><span class="hs-identifier hs-var">fst</span></a></span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960431"><span class="hs-identifier hs-var">orig_pairs</span></a></span><span>
</span><span id="line-905"></span><span>
</span><span id="line-906"></span><span>    </span><span class="hs-comment">-- See Note [Initialising strictness]</span><span>
</span><span id="line-907"></span><span>    </span><span id="local-6989586621680960429"><span class="annot"><span class="annottext">initial_pairs :: [(Var, CoreExpr)]
</span><a href="#local-6989586621680960429"><span class="hs-identifier hs-var hs-var">initial_pairs</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; Bool
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_virgin"><span class="hs-identifier hs-var hs-var">ae_virgin</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960433"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; StrictSig -&gt; Var
</span><a href="GHC.Types.Id.html#setIdStrictness"><span class="hs-identifier hs-var">setIdStrictness</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960426"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">StrictSig
</span><a href="GHC.Types.Demand.html#botSig"><span class="hs-identifier hs-var">botSig</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960424"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680960426"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960426"><span class="hs-identifier hs-var">id</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960424"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960424"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960431"><span class="hs-identifier hs-var">orig_pairs</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-908"></span><span>                  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960431"><span class="hs-identifier hs-var">orig_pairs</span></a></span><span>
</span><span id="line-909"></span><span>
</span><span id="line-910"></span><span>    </span><span class="hs-comment">-- If fixed-point iteration does not yield a result we use this instead</span><span>
</span><span id="line-911"></span><span>    </span><span class="hs-comment">-- See Note [Safe abortion in the fixed-point iteration]</span><span>
</span><span id="line-912"></span><span>    </span><span class="annot"><a href="#local-6989586621680960423"><span class="hs-identifier hs-type">abort</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#DmdEnv"><span class="hs-identifier hs-type">DmdEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-913"></span><span>    </span><span id="local-6989586621680960423"><span class="annot"><span class="annottext">abort :: (AnalEnv, DmdEnv, [(Var, CoreExpr)])
</span><a href="#local-6989586621680960423"><span class="hs-identifier hs-var hs-var">abort</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960433"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960422"><span class="hs-identifier hs-var">lazy_fv'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960421"><span class="hs-identifier hs-var">zapped_pairs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-914"></span><span>      </span><span class="hs-keyword">where</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680960420"><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960420"><span class="hs-identifier hs-var">lazy_fv</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960419"><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960419"><span class="hs-identifier hs-var">pairs'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; [(Var, CoreExpr)] -&gt; (DmdEnv, [(Var, CoreExpr)])
</span><a href="#local-6989586621680960418"><span class="hs-identifier hs-var">step</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[(Var, CoreExpr)] -&gt; [(Var, CoreExpr)]
</span><a href="#local-6989586621680960417"><span class="hs-identifier hs-var">zapIdStrictness</span></a></span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960431"><span class="hs-identifier hs-var">orig_pairs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-915"></span><span>            </span><span class="hs-comment">-- Note [Lazy and unleashable free variables]</span><span>
</span><span id="line-916"></span><span>            </span><span id="local-6989586621680960416"><span class="annot"><span class="annottext">non_lazy_fvs :: DmdEnv
</span><a href="#local-6989586621680960416"><span class="hs-identifier hs-var hs-var">non_lazy_fvs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[DmdEnv] -&gt; DmdEnv
forall a. [VarEnv a] -&gt; VarEnv a
</span><a href="GHC.Types.Var.Env.html#plusVarEnvList"><span class="hs-identifier hs-var">plusVarEnvList</span></a></span><span> </span><span class="annot"><span class="annottext">([DmdEnv] -&gt; DmdEnv) -&gt; [DmdEnv] -&gt; DmdEnv
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">((Var, CoreExpr) -&gt; DmdEnv) -&gt; [(Var, CoreExpr)] -&gt; [DmdEnv]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">StrictSig -&gt; DmdEnv
</span><a href="GHC.Types.Demand.html#strictSigDmdEnv"><span class="hs-identifier hs-var">strictSigDmdEnv</span></a></span><span> </span><span class="annot"><span class="annottext">(StrictSig -&gt; DmdEnv)
-&gt; ((Var, CoreExpr) -&gt; StrictSig) -&gt; (Var, CoreExpr) -&gt; DmdEnv
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">Var -&gt; StrictSig
</span><a href="GHC.Types.Id.html#idStrictness"><span class="hs-identifier hs-var">idStrictness</span></a></span><span> </span><span class="annot"><span class="annottext">(Var -&gt; StrictSig)
-&gt; ((Var, CoreExpr) -&gt; Var) -&gt; (Var, CoreExpr) -&gt; StrictSig
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">(Var, CoreExpr) -&gt; Var
forall a b. (a, b) -&gt; a
</span><a href="../../base/src/Data.Tuple.html#fst"><span class="hs-identifier hs-var">fst</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960419"><span class="hs-identifier hs-var">pairs'</span></a></span><span>
</span><span id="line-917"></span><span>            </span><span id="local-6989586621680960422"><span class="annot"><span class="annottext">lazy_fv' :: DmdEnv
</span><a href="#local-6989586621680960422"><span class="hs-identifier hs-var hs-var">lazy_fv'</span></a></span></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960420"><span class="hs-identifier hs-var">lazy_fv</span></a></span><span> </span><span class="annot"><span class="annottext">DmdEnv -&gt; DmdEnv -&gt; DmdEnv
forall a. VarEnv a -&gt; VarEnv a -&gt; VarEnv a
</span><a href="GHC.Types.Var.Env.html#plusVarEnv"><span class="hs-operator hs-var">`plusVarEnv`</span></a></span><span> </span><span class="annot"><span class="annottext">(Demand -&gt; Demand) -&gt; DmdEnv -&gt; DmdEnv
forall a b. (a -&gt; b) -&gt; VarEnv a -&gt; VarEnv b
</span><a href="GHC.Types.Var.Env.html#mapVarEnv"><span class="hs-identifier hs-var">mapVarEnv</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Demand -&gt; Demand -&gt; Demand
forall a b. a -&gt; b -&gt; a
</span><a href="../../base/src/GHC.Base.html#const"><span class="hs-identifier hs-var">const</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="GHC.Types.Demand.html#topDmd"><span class="hs-identifier hs-var">topDmd</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960416"><span class="hs-identifier hs-var">non_lazy_fvs</span></a></span><span>
</span><span id="line-918"></span><span>            </span><span id="local-6989586621680960421"><span class="annot"><span class="annottext">zapped_pairs :: [(Var, CoreExpr)]
</span><a href="#local-6989586621680960421"><span class="hs-identifier hs-var hs-var">zapped_pairs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)] -&gt; [(Var, CoreExpr)]
</span><a href="#local-6989586621680960417"><span class="hs-identifier hs-var">zapIdStrictness</span></a></span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960419"><span class="hs-identifier hs-var">pairs'</span></a></span><span>
</span><span id="line-919"></span><span>
</span><span id="line-920"></span><span>    </span><span class="hs-comment">-- The fixed-point varies the idStrictness field of the binders, and terminates if that</span><span>
</span><span id="line-921"></span><span>    </span><span class="hs-comment">-- annotation does not change any more.</span><span>
</span><span id="line-922"></span><span>    </span><span class="annot"><a href="#local-6989586621680960430"><span class="hs-identifier hs-type">loop</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#DmdEnv"><span class="hs-identifier hs-type">DmdEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-923"></span><span>    </span><span id="local-6989586621680960430"><span class="annot"><span class="annottext">loop :: Arity -&gt; [(Var, CoreExpr)] -&gt; (AnalEnv, DmdEnv, [(Var, CoreExpr)])
</span><a href="#local-6989586621680960430"><span class="hs-identifier hs-var hs-var">loop</span></a></span></span><span> </span><span id="local-6989586621680960409"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680960409"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span id="local-6989586621680960408"><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960408"><span class="hs-identifier hs-var">pairs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-comment">-- pprTrace &quot;dmdFix&quot; (ppr n &lt;+&gt; vcat [ ppr id &lt;+&gt; ppr (idStrictness id)</span><span>
</span><span id="line-924"></span><span>                   </span><span class="hs-comment">--                                     | (id,_)&lt;- pairs]) $</span><span>
</span><span id="line-925"></span><span>                   </span><span class="annot"><span class="annottext">Arity -&gt; [(Var, CoreExpr)] -&gt; (AnalEnv, DmdEnv, [(Var, CoreExpr)])
</span><a href="#local-6989586621680960407"><span class="hs-identifier hs-var">loop'</span></a></span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680960409"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960408"><span class="hs-identifier hs-var">pairs</span></a></span><span>
</span><span id="line-926"></span><span>
</span><span id="line-927"></span><span>    </span><span id="local-6989586621680960407"><span class="annot"><span class="annottext">loop' :: Arity -&gt; [(Var, CoreExpr)] -&gt; (AnalEnv, DmdEnv, [(Var, CoreExpr)])
</span><a href="#local-6989586621680960407"><span class="hs-identifier hs-var hs-var">loop'</span></a></span></span><span> </span><span id="local-6989586621680960402"><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680960402"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span id="local-6989586621680960401"><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960401"><span class="hs-identifier hs-var">pairs</span></a></span></span><span>
</span><span id="line-928"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680960400"><span class="hs-identifier hs-var">found_fixpoint</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960399"><span class="hs-identifier hs-var">final_anal_env</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960398"><span class="hs-identifier hs-var">lazy_fv</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960397"><span class="hs-identifier hs-var">pairs'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-929"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680960402"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">10</span></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(AnalEnv, DmdEnv, [(Var, CoreExpr)])
</span><a href="#local-6989586621680960423"><span class="hs-identifier hs-var">abort</span></a></span><span>
</span><span id="line-930"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity -&gt; [(Var, CoreExpr)] -&gt; (AnalEnv, DmdEnv, [(Var, CoreExpr)])
</span><a href="#local-6989586621680960430"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680960402"><span class="hs-identifier hs-var">n</span></a></span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Arity
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960397"><span class="hs-identifier hs-var">pairs'</span></a></span><span>
</span><span id="line-931"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-932"></span><span>        </span><span id="local-6989586621680960400"><span class="annot"><span class="annottext">found_fixpoint :: Bool
</span><a href="#local-6989586621680960400"><span class="hs-identifier hs-var hs-var">found_fixpoint</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">((Var, CoreExpr) -&gt; StrictSig) -&gt; [(Var, CoreExpr)] -&gt; [StrictSig]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; StrictSig
</span><a href="GHC.Types.Id.html#idStrictness"><span class="hs-identifier hs-var">idStrictness</span></a></span><span> </span><span class="annot"><span class="annottext">(Var -&gt; StrictSig)
-&gt; ((Var, CoreExpr) -&gt; Var) -&gt; (Var, CoreExpr) -&gt; StrictSig
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">(Var, CoreExpr) -&gt; Var
forall a b. (a, b) -&gt; a
</span><a href="../../base/src/Data.Tuple.html#fst"><span class="hs-identifier hs-var">fst</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960397"><span class="hs-identifier hs-var">pairs'</span></a></span><span> </span><span class="annot"><span class="annottext">[StrictSig] -&gt; [StrictSig] -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">((Var, CoreExpr) -&gt; StrictSig) -&gt; [(Var, CoreExpr)] -&gt; [StrictSig]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; StrictSig
</span><a href="GHC.Types.Id.html#idStrictness"><span class="hs-identifier hs-var">idStrictness</span></a></span><span> </span><span class="annot"><span class="annottext">(Var -&gt; StrictSig)
-&gt; ((Var, CoreExpr) -&gt; Var) -&gt; (Var, CoreExpr) -&gt; StrictSig
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">(Var, CoreExpr) -&gt; Var
forall a b. (a, b) -&gt; a
</span><a href="../../base/src/Data.Tuple.html#fst"><span class="hs-identifier hs-var">fst</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960401"><span class="hs-identifier hs-var">pairs</span></a></span><span>
</span><span id="line-933"></span><span>        </span><span id="local-6989586621680960389"><span class="annot"><span class="annottext">first_round :: Bool
</span><a href="#local-6989586621680960389"><span class="hs-identifier hs-var hs-var">first_round</span></a></span></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Arity
</span><a href="#local-6989586621680960402"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Arity -&gt; Arity -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Arity
</span><span class="hs-number">1</span></span><span>
</span><span id="line-934"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621680960398"><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960398"><span class="hs-identifier hs-var">lazy_fv</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960397"><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960397"><span class="hs-identifier hs-var">pairs'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; [(Var, CoreExpr)] -&gt; (DmdEnv, [(Var, CoreExpr)])
</span><a href="#local-6989586621680960418"><span class="hs-identifier hs-var">step</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680960389"><span class="hs-identifier hs-var">first_round</span></a></span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960401"><span class="hs-identifier hs-var">pairs</span></a></span><span>
</span><span id="line-935"></span><span>        </span><span id="local-6989586621680960399"><span class="annot"><span class="annottext">final_anal_env :: AnalEnv
</span><a href="#local-6989586621680960399"><span class="hs-identifier hs-var hs-var">final_anal_env</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TopLevelFlag -&gt; AnalEnv -&gt; [Var] -&gt; AnalEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#extendAnalEnvs"><span class="hs-identifier hs-var">extendAnalEnvs</span></a></span><span> </span><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680960434"><span class="hs-identifier hs-var">top_lvl</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960433"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">((Var, CoreExpr) -&gt; Var) -&gt; [(Var, CoreExpr)] -&gt; [Var]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">(Var, CoreExpr) -&gt; Var
forall a b. (a, b) -&gt; a
</span><a href="../../base/src/Data.Tuple.html#fst"><span class="hs-identifier hs-var">fst</span></a></span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960397"><span class="hs-identifier hs-var">pairs'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-936"></span><span>
</span><span id="line-937"></span><span>    </span><span class="annot"><a href="#local-6989586621680960418"><span class="hs-identifier hs-type">step</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Demand.html#DmdEnv"><span class="hs-identifier hs-type">DmdEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-938"></span><span>    </span><span id="local-6989586621680960418"><span class="annot"><span class="annottext">step :: Bool -&gt; [(Var, CoreExpr)] -&gt; (DmdEnv, [(Var, CoreExpr)])
</span><a href="#local-6989586621680960418"><span class="hs-identifier hs-var hs-var">step</span></a></span></span><span> </span><span id="local-6989586621680960387"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680960387"><span class="hs-identifier hs-var">first_round</span></a></span></span><span> </span><span id="local-6989586621680960386"><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960386"><span class="hs-identifier hs-var">pairs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960385"><span class="hs-identifier hs-var">lazy_fv</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960384"><span class="hs-identifier hs-var">pairs'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-939"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-940"></span><span>        </span><span class="hs-comment">-- In all but the first iteration, delete the virgin flag</span><span>
</span><span id="line-941"></span><span>        </span><span id="local-6989586621680960383"><span class="annot"><span class="annottext">start_env :: AnalEnv
</span><a href="#local-6989586621680960383"><span class="hs-identifier hs-var hs-var">start_env</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680960387"><span class="hs-identifier hs-var">first_round</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960433"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-942"></span><span>                  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; AnalEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#nonVirgin"><span class="hs-identifier hs-var">nonVirgin</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960433"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-943"></span><span>
</span><span id="line-944"></span><span>        </span><span id="local-6989586621680960381"><span class="annot"><span class="annottext">start :: (AnalEnv, DmdEnv)
</span><a href="#local-6989586621680960381"><span class="hs-identifier hs-var hs-var">start</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TopLevelFlag -&gt; AnalEnv -&gt; [Var] -&gt; AnalEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#extendAnalEnvs"><span class="hs-identifier hs-var">extendAnalEnvs</span></a></span><span> </span><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680960434"><span class="hs-identifier hs-var">top_lvl</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960383"><span class="hs-identifier hs-var">start_env</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">((Var, CoreExpr) -&gt; Var) -&gt; [(Var, CoreExpr)] -&gt; [Var]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">(Var, CoreExpr) -&gt; Var
forall a b. (a, b) -&gt; a
</span><a href="../../base/src/Data.Tuple.html#fst"><span class="hs-identifier hs-var">fst</span></a></span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960386"><span class="hs-identifier hs-var">pairs</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="GHC.Types.Demand.html#emptyDmdEnv"><span class="hs-identifier hs-var">emptyDmdEnv</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-945"></span><span>
</span><span id="line-946"></span><span>        </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">AnalEnv
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span id="local-6989586621680960385"><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960385"><span class="hs-identifier hs-var">lazy_fv</span></a></span></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960384"><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960384"><span class="hs-identifier hs-var">pairs'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">((AnalEnv, DmdEnv)
 -&gt; (Var, CoreExpr) -&gt; ((AnalEnv, DmdEnv), (Var, CoreExpr)))
-&gt; (AnalEnv, DmdEnv)
-&gt; [(Var, CoreExpr)]
-&gt; ((AnalEnv, DmdEnv), [(Var, CoreExpr)])
forall (t :: * -&gt; *) s a b.
Traversable t =&gt;
(s -&gt; a -&gt; (s, b)) -&gt; s -&gt; t a -&gt; (s, t b)
</span><a href="../../base/src/Data.Traversable.html#mapAccumL"><span class="hs-identifier hs-var">mapAccumL</span></a></span><span> </span><span class="annot"><span class="annottext">(AnalEnv, DmdEnv)
-&gt; (Var, CoreExpr) -&gt; ((AnalEnv, DmdEnv), (Var, CoreExpr))
</span><a href="#local-6989586621680960378"><span class="hs-identifier hs-var">my_downRhs</span></a></span><span> </span><span class="annot"><span class="annottext">(AnalEnv, DmdEnv)
</span><a href="#local-6989586621680960381"><span class="hs-identifier hs-var">start</span></a></span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960386"><span class="hs-identifier hs-var">pairs</span></a></span><span>
</span><span id="line-947"></span><span>                </span><span class="hs-comment">-- mapAccumL: Use the new signature to do the next pair</span><span>
</span><span id="line-948"></span><span>                </span><span class="hs-comment">-- The occurrence analyser has arranged them in a good order</span><span>
</span><span id="line-949"></span><span>                </span><span class="hs-comment">-- so this can significantly reduce the number of iterations needed</span><span>
</span><span id="line-950"></span><span>
</span><span id="line-951"></span><span>        </span><span id="local-6989586621680960378"><span class="annot"><span class="annottext">my_downRhs :: (AnalEnv, DmdEnv)
-&gt; (Var, CoreExpr) -&gt; ((AnalEnv, DmdEnv), (Var, CoreExpr))
</span><a href="#local-6989586621680960378"><span class="hs-identifier hs-var hs-var">my_downRhs</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680960377"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960377"><span class="hs-identifier hs-var">env</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960376"><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960376"><span class="hs-identifier hs-var">lazy_fv</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680960375"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960375"><span class="hs-identifier hs-var">id</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680960374"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960374"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-952"></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960373"><span class="hs-identifier hs-var">env'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960372"><span class="hs-identifier hs-var">lazy_fv'</span></a></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960371"><span class="hs-identifier hs-var">id'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960370"><span class="hs-identifier hs-var">rhs'</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-953"></span><span>          </span><span class="hs-keyword">where</span><span>
</span><span id="line-954"></span><span>            </span><span class="hs-special">(</span><span id="local-6989586621680960369"><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960369"><span class="hs-identifier hs-var">lazy_fv1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960368"><span class="annot"><span class="annottext">StrictSig
</span><a href="#local-6989586621680960368"><span class="hs-identifier hs-var">sig</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960370"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960370"><span class="hs-identifier hs-var">rhs'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe [Var]
-&gt; AnalEnv
-&gt; CleanDemand
-&gt; Var
-&gt; CoreExpr
-&gt; (DmdEnv, StrictSig, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalRhsLetDown"><span class="hs-identifier hs-var">dmdAnalRhsLetDown</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Var] -&gt; Maybe [Var]
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960428"><span class="hs-identifier hs-var">bndrs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960377"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">CleanDemand
</span><a href="#local-6989586621680960432"><span class="hs-identifier hs-var">let_dmd</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960375"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960374"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-955"></span><span>            </span><span id="local-6989586621680960372"><span class="annot"><span class="annottext">lazy_fv' :: DmdEnv
</span><a href="#local-6989586621680960372"><span class="hs-identifier hs-var hs-var">lazy_fv'</span></a></span></span><span>              </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Demand -&gt; Demand -&gt; Demand) -&gt; DmdEnv -&gt; DmdEnv -&gt; DmdEnv
forall a. (a -&gt; a -&gt; a) -&gt; VarEnv a -&gt; VarEnv a -&gt; VarEnv a
</span><a href="GHC.Types.Var.Env.html#plusVarEnv_C"><span class="hs-identifier hs-var">plusVarEnv_C</span></a></span><span> </span><span class="annot"><span class="annottext">Demand -&gt; Demand -&gt; Demand
</span><a href="GHC.Types.Demand.html#bothDmd"><span class="hs-identifier hs-var">bothDmd</span></a></span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960376"><span class="hs-identifier hs-var">lazy_fv</span></a></span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960369"><span class="hs-identifier hs-var">lazy_fv1</span></a></span><span>
</span><span id="line-956"></span><span>            </span><span id="local-6989586621680960373"><span class="annot"><span class="annottext">env' :: AnalEnv
</span><a href="#local-6989586621680960373"><span class="hs-identifier hs-var hs-var">env'</span></a></span></span><span>                  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TopLevelFlag -&gt; AnalEnv -&gt; Var -&gt; StrictSig -&gt; AnalEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#extendAnalEnv"><span class="hs-identifier hs-var">extendAnalEnv</span></a></span><span> </span><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680960434"><span class="hs-identifier hs-var">top_lvl</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960377"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960375"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">StrictSig
</span><a href="#local-6989586621680960368"><span class="hs-identifier hs-var">sig</span></a></span><span>
</span><span id="line-957"></span><span>            </span><span id="local-6989586621680960371"><span class="annot"><span class="annottext">id' :: Var
</span><a href="#local-6989586621680960371"><span class="hs-identifier hs-var hs-var">id'</span></a></span></span><span>                   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var -&gt; StrictSig -&gt; Var
</span><a href="GHC.Types.Id.html#setIdStrictness"><span class="hs-identifier hs-var">setIdStrictness</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960375"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">StrictSig
</span><a href="#local-6989586621680960368"><span class="hs-identifier hs-var">sig</span></a></span><span>
</span><span id="line-958"></span><span>
</span><span id="line-959"></span><span>    </span><span class="annot"><a href="#local-6989586621680960417"><span class="hs-identifier hs-type">zapIdStrictness</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#CoreExpr"><span class="hs-identifier hs-type">CoreExpr</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-960"></span><span>    </span><span id="local-6989586621680960417"><span class="annot"><span class="annottext">zapIdStrictness :: [(Var, CoreExpr)] -&gt; [(Var, CoreExpr)]
</span><a href="#local-6989586621680960417"><span class="hs-identifier hs-var hs-var">zapIdStrictness</span></a></span></span><span> </span><span id="local-6989586621680960365"><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960365"><span class="hs-identifier hs-var">pairs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; StrictSig -&gt; Var
</span><a href="GHC.Types.Id.html#setIdStrictness"><span class="hs-identifier hs-var">setIdStrictness</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960364"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">StrictSig
</span><a href="GHC.Types.Demand.html#nopSig"><span class="hs-identifier hs-var">nopSig</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960362"><span class="hs-identifier hs-var">rhs</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680960364"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960364"><span class="hs-identifier hs-var">id</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960362"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960362"><span class="hs-identifier hs-var">rhs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[(Var, CoreExpr)]
</span><a href="#local-6989586621680960365"><span class="hs-identifier hs-var">pairs</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-961"></span><span>
</span><span id="line-962"></span><span class="hs-comment">{- Note [Safe abortion in the fixed-point iteration]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fixed-point iteration may fail to terminate. But we cannot simply give up and
return the environment and code unchanged! We still need to do one additional
round, for two reasons:

 * To get information on used free variables (both lazy and strict!)
   (see Note [Lazy and unleashable free variables])
 * To ensure that all expressions have been traversed at least once, and any left-over
   strictness annotations have been updated.

This final iteration does not add the variables to the strictness signature
environment, which effectively assigns them 'nopSig' (see &quot;getStrictness&quot;)

Note [Trimming a demand to a type]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There are two reasons we sometimes trim a demand to match a type.
  1. GADTs
  2. Recursive products and widening

More on both below.  But the botttom line is: we really don't want to
have a binder whose demand is more deeply-nested than its type
&quot;allows&quot;. So in findBndrDmd we call trimToType and findTypeShape to
trim the demand on the binder to a form that matches the type

Now to the reasons. For (1) consider
  f :: a -&gt; Bool
  f x = case ... of
          A g1 -&gt; case (x |&gt; g1) of (p,q) -&gt; ...
          B    -&gt; error &quot;urk&quot;

where A,B are the constructors of a GADT.  We'll get a U(U,U) demand
on x from the A branch, but that's a stupid demand for x itself, which
has type 'a'. Indeed we get ASSERTs going off (notably in
splitUseProdDmd, #8569).

For (2) consider
  data T = MkT Int T    -- A recursive product
  f :: Int -&gt; T -&gt; Int
  f 0 _         = 0
  f _ (MkT n t) = f n t

Here f is lazy in T, but its *usage* is infinite: U(U,U(U,U(U, ...))).
Notice that this happens becuase T is a product type, and is recrusive.
If we are not careful, we'll fail to iterate to a fixpoint in dmdFix,
and bale out entirely, which is inefficient and over-conservative.

Worse, as we discovered in #18304, the size of the usages we compute
can grow /exponentially/, so even 10 iterations costs far too much.
Especially since we then discard the result.

To avoid this we use the same findTypeShape function as for (1), but
arrange that it trims the demand if it encounters the same type constructor
twice (or three times, etc).  We use our standard RecTcChecker mechanism
for this -- see GHC.Core.Opt.WorkWrap.Utils.findTypeShape.

This is usually call &quot;widening&quot;.  We could do it just in dmdFix, but
since are doing this findTypeShape business /anyway/ because of (1),
and it has all the right information to hand, it's extremely
convenient to do it there.

-}</span><span>
</span><span id="line-1025"></span><span>
</span><span id="line-1026"></span><span class="hs-comment">{- *********************************************************************
*                                                                      *
                 Strictness signatures and types
*                                                                      *
********************************************************************* -}</span><span>
</span><span id="line-1031"></span><span>
</span><span id="line-1032"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#unitDmdType"><span class="hs-identifier hs-type">unitDmdType</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#DmdEnv"><span class="hs-identifier hs-type">DmdEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span>
</span><span id="line-1033"></span><span id="unitDmdType"><span class="annot"><span class="annottext">unitDmdType :: DmdEnv -&gt; DmdType
</span><a href="GHC.Core.Opt.DmdAnal.html#unitDmdType"><span class="hs-identifier hs-var hs-var">unitDmdType</span></a></span></span><span> </span><span id="local-6989586621680960361"><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960361"><span class="hs-identifier hs-var">dmd_env</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdEnv -&gt; [Demand] -&gt; Divergence -&gt; DmdType
</span><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-var">DmdType</span></a></span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960361"><span class="hs-identifier hs-var">dmd_env</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">Divergence
</span><a href="GHC.Types.Demand.html#topDiv"><span class="hs-identifier hs-var">topDiv</span></a></span><span>
</span><span id="line-1034"></span><span>
</span><span id="line-1035"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#coercionDmdEnv"><span class="hs-identifier hs-type">coercionDmdEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Coercion"><span class="hs-identifier hs-type">Coercion</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#DmdEnv"><span class="hs-identifier hs-type">DmdEnv</span></a></span><span>
</span><span id="line-1036"></span><span id="coercionDmdEnv"><span class="annot"><span class="annottext">coercionDmdEnv :: Coercion -&gt; DmdEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#coercionDmdEnv"><span class="hs-identifier hs-var hs-var">coercionDmdEnv</span></a></span></span><span> </span><span id="local-6989586621680960359"><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680960359"><span class="hs-identifier hs-var">co</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Var -&gt; Demand) -&gt; VarEnv Var -&gt; DmdEnv
forall a b. (a -&gt; b) -&gt; VarEnv a -&gt; VarEnv b
</span><a href="GHC.Types.Var.Env.html#mapVarEnv"><span class="hs-identifier hs-var">mapVarEnv</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Demand -&gt; Var -&gt; Demand
forall a b. a -&gt; b -&gt; a
</span><a href="../../base/src/GHC.Base.html#const"><span class="hs-identifier hs-var">const</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="GHC.Types.Demand.html#topDmd"><span class="hs-identifier hs-var">topDmd</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IdSet -&gt; VarEnv Var
forall a. UniqSet a -&gt; UniqFM a a
</span><a href="GHC.Types.Unique.Set.html#getUniqSet"><span class="hs-identifier hs-var">getUniqSet</span></a></span><span> </span><span class="annot"><span class="annottext">(IdSet -&gt; VarEnv Var) -&gt; IdSet -&gt; VarEnv Var
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion -&gt; IdSet
</span><a href="GHC.Core.TyCo.FVs.html#coVarsOfCo"><span class="hs-identifier hs-var">coVarsOfCo</span></a></span><span> </span><span class="annot"><span class="annottext">Coercion
</span><a href="#local-6989586621680960359"><span class="hs-identifier hs-var">co</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1037"></span><span>                    </span><span class="hs-comment">-- The VarSet from coVarsOfCo is really a VarEnv Var</span><span>
</span><span id="line-1038"></span><span>
</span><span id="line-1039"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#addVarDmd"><span class="hs-identifier hs-type">addVarDmd</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#Demand"><span class="hs-identifier hs-type">Demand</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span>
</span><span id="line-1040"></span><span id="addVarDmd"><span class="annot"><span class="annottext">addVarDmd :: DmdType -&gt; Var -&gt; Demand -&gt; DmdType
</span><a href="GHC.Core.Opt.DmdAnal.html#addVarDmd"><span class="hs-identifier hs-var hs-var">addVarDmd</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span> </span><span id="local-6989586621680960357"><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960357"><span class="hs-identifier hs-var">fv</span></a></span></span><span> </span><span id="local-6989586621680960356"><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960356"><span class="hs-identifier hs-var">ds</span></a></span></span><span> </span><span id="local-6989586621680960355"><span class="annot"><span class="annottext">Divergence
</span><a href="#local-6989586621680960355"><span class="hs-identifier hs-var">res</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680960354"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960354"><span class="hs-identifier hs-var">var</span></a></span></span><span> </span><span id="local-6989586621680960353"><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960353"><span class="hs-identifier hs-var">dmd</span></a></span></span><span>
</span><span id="line-1041"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdEnv -&gt; [Demand] -&gt; Divergence -&gt; DmdType
</span><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-var">DmdType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Demand -&gt; Demand -&gt; Demand) -&gt; DmdEnv -&gt; Var -&gt; Demand -&gt; DmdEnv
forall a. (a -&gt; a -&gt; a) -&gt; VarEnv a -&gt; Var -&gt; a -&gt; VarEnv a
</span><a href="GHC.Types.Var.Env.html#extendVarEnv_C"><span class="hs-identifier hs-var">extendVarEnv_C</span></a></span><span> </span><span class="annot"><span class="annottext">Demand -&gt; Demand -&gt; Demand
</span><a href="GHC.Types.Demand.html#bothDmd"><span class="hs-identifier hs-var">bothDmd</span></a></span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960357"><span class="hs-identifier hs-var">fv</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960354"><span class="hs-identifier hs-var">var</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960353"><span class="hs-identifier hs-var">dmd</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960356"><span class="hs-identifier hs-var">ds</span></a></span><span> </span><span class="annot"><span class="annottext">Divergence
</span><a href="#local-6989586621680960355"><span class="hs-identifier hs-var">res</span></a></span><span>
</span><span id="line-1042"></span><span>
</span><span id="line-1043"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#addLazyFVs"><span class="hs-identifier hs-type">addLazyFVs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#DmdEnv"><span class="hs-identifier hs-type">DmdEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span>
</span><span id="line-1044"></span><span id="addLazyFVs"><span class="annot"><span class="annottext">addLazyFVs :: DmdType -&gt; DmdEnv -&gt; DmdType
</span><a href="GHC.Core.Opt.DmdAnal.html#addLazyFVs"><span class="hs-identifier hs-var hs-var">addLazyFVs</span></a></span></span><span> </span><span id="local-6989586621680960351"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960351"><span class="hs-identifier hs-var">dmd_ty</span></a></span></span><span> </span><span id="local-6989586621680960350"><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960350"><span class="hs-identifier hs-var">lazy_fvs</span></a></span></span><span>
</span><span id="line-1045"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960351"><span class="hs-identifier hs-var">dmd_ty</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; BothDmdArg -&gt; DmdType
</span><a href="GHC.Types.Demand.html#bothDmdType"><span class="hs-operator hs-var">`bothDmdType`</span></a></span><span> </span><span class="annot"><span class="annottext">DmdEnv -&gt; BothDmdArg
</span><a href="GHC.Types.Demand.html#mkBothDmdArg"><span class="hs-identifier hs-var">mkBothDmdArg</span></a></span><span> </span><span class="annot"><span class="annottext">DmdEnv
</span><a href="#local-6989586621680960350"><span class="hs-identifier hs-var">lazy_fvs</span></a></span><span>
</span><span id="line-1046"></span><span>        </span><span class="hs-comment">-- Using bothDmdType (rather than just both'ing the envs)</span><span>
</span><span id="line-1047"></span><span>        </span><span class="hs-comment">-- is vital.  Consider</span><span>
</span><span id="line-1048"></span><span>        </span><span class="hs-comment">--      let f = \x -&gt; (x,y)</span><span>
</span><span id="line-1049"></span><span>        </span><span class="hs-comment">--      in  error (f 3)</span><span>
</span><span id="line-1050"></span><span>        </span><span class="hs-comment">-- Here, y is treated as a lazy-fv of f, but we must `bothDmd` that L</span><span>
</span><span id="line-1051"></span><span>        </span><span class="hs-comment">-- demand with the bottom coming up from 'error'</span><span>
</span><span id="line-1052"></span><span>        </span><span class="hs-comment">--</span><span>
</span><span id="line-1053"></span><span>        </span><span class="hs-comment">-- I got a loop in the fixpointer without this, due to an interaction</span><span>
</span><span id="line-1054"></span><span>        </span><span class="hs-comment">-- with the lazy_fv filtering in dmdAnalRhsLetDown.  Roughly, it was</span><span>
</span><span id="line-1055"></span><span>        </span><span class="hs-comment">--      letrec f n x</span><span>
</span><span id="line-1056"></span><span>        </span><span class="hs-comment">--          = letrec g y = x `fatbar`</span><span>
</span><span id="line-1057"></span><span>        </span><span class="hs-comment">--                         letrec h z = z + ...g...</span><span>
</span><span id="line-1058"></span><span>        </span><span class="hs-comment">--                         in h (f (n-1) x)</span><span>
</span><span id="line-1059"></span><span>        </span><span class="hs-comment">--      in ...</span><span>
</span><span id="line-1060"></span><span>        </span><span class="hs-comment">-- In the initial iteration for f, f=Bot</span><span>
</span><span id="line-1061"></span><span>        </span><span class="hs-comment">-- Suppose h is found to be strict in z, but the occurrence of g in its RHS</span><span>
</span><span id="line-1062"></span><span>        </span><span class="hs-comment">-- is lazy.  Now consider the fixpoint iteration for g, esp the demands it</span><span>
</span><span id="line-1063"></span><span>        </span><span class="hs-comment">-- places on its free variables.  Suppose it places none.  Then the</span><span>
</span><span id="line-1064"></span><span>        </span><span class="hs-comment">--      x `fatbar` ...call to h...</span><span>
</span><span id="line-1065"></span><span>        </span><span class="hs-comment">-- will give a x-&gt;V demand for x.  That turns into a L demand for x,</span><span>
</span><span id="line-1066"></span><span>        </span><span class="hs-comment">-- which floats out of the defn for h.  Without the modifyEnv, that</span><span>
</span><span id="line-1067"></span><span>        </span><span class="hs-comment">-- L demand doesn't get both'd with the Bot coming up from the inner</span><span>
</span><span id="line-1068"></span><span>        </span><span class="hs-comment">-- call to f.  So we just get an L demand for x for g.</span><span>
</span><span id="line-1069"></span><span>
</span><span id="line-1070"></span><span class="hs-comment">{-
Note [Do not strictify the argument dictionaries of a dfun]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The typechecker can tie recursive knots involving dfuns, so we do the
conservative thing and refrain from strictifying a dfun's argument
dictionaries.
-}</span><span>
</span><span id="line-1077"></span><span>
</span><span id="line-1078"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#setBndrsDemandInfo"><span class="hs-identifier hs-type">setBndrsDemandInfo</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Demand.html#Demand"><span class="hs-identifier hs-type">Demand</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-1079"></span><span id="setBndrsDemandInfo"><span class="annot"><span class="annottext">setBndrsDemandInfo :: [Var] -&gt; [Demand] -&gt; [Var]
</span><a href="GHC.Core.Opt.DmdAnal.html#setBndrsDemandInfo"><span class="hs-identifier hs-var hs-var">setBndrsDemandInfo</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680960349"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960349"><span class="hs-identifier hs-var">b</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680960348"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960348"><span class="hs-identifier hs-var">bs</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621680960347"><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960347"><span class="hs-identifier hs-var">ds</span></a></span></span><span>
</span><span id="line-1080"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Types.Var.html#isTyVar"><span class="hs-identifier hs-var">isTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960349"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960349"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="annot"><span class="annottext">Var -&gt; [Var] -&gt; [Var]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[Var] -&gt; [Demand] -&gt; [Var]
</span><a href="GHC.Core.Opt.DmdAnal.html#setBndrsDemandInfo"><span class="hs-identifier hs-var">setBndrsDemandInfo</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960348"><span class="hs-identifier hs-var">bs</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960347"><span class="hs-identifier hs-var">ds</span></a></span><span>
</span><span id="line-1081"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#setBndrsDemandInfo"><span class="hs-identifier hs-var">setBndrsDemandInfo</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680960346"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960346"><span class="hs-identifier hs-var">b</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680960345"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960345"><span class="hs-identifier hs-var">bs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680960344"><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960344"><span class="hs-identifier hs-var">d</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680960343"><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960343"><span class="hs-identifier hs-var">ds</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1082"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621680960342"><span class="annot"><span class="annottext">new_info :: Var
</span><a href="#local-6989586621680960342"><span class="hs-identifier hs-var hs-var">new_info</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Demand -&gt; Var
</span><a href="GHC.Types.Id.html#setIdDemandInfo"><span class="hs-identifier hs-var">setIdDemandInfo</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960346"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960344"><span class="hs-identifier hs-var">d</span></a></span><span>
</span><span id="line-1083"></span><span>        </span><span class="hs-glyph">!</span><span id="local-6989586621680960341"><span class="annot"><span class="annottext">vars :: [Var]
</span><a href="#local-6989586621680960341"><span class="hs-identifier hs-var hs-var">vars</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Var] -&gt; [Demand] -&gt; [Var]
</span><a href="GHC.Core.Opt.DmdAnal.html#setBndrsDemandInfo"><span class="hs-identifier hs-var">setBndrsDemandInfo</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960345"><span class="hs-identifier hs-var">bs</span></a></span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960343"><span class="hs-identifier hs-var">ds</span></a></span><span>
</span><span id="line-1084"></span><span>    </span><span class="hs-keyword">in</span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960342"><span class="hs-identifier hs-var">new_info</span></a></span><span> </span><span class="annot"><span class="annottext">Var -&gt; [Var] -&gt; [Var]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960341"><span class="hs-identifier hs-var">vars</span></a></span><span>
</span><span id="line-1085"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#setBndrsDemandInfo"><span class="hs-identifier hs-var">setBndrsDemandInfo</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span id="local-6989586621680960340"><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960340"><span class="hs-identifier hs-var">ds</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">null</span><span> </span><span class="hs-identifier">ds</span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-1086"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#setBndrsDemandInfo"><span class="hs-identifier hs-var">setBndrsDemandInfo</span></a></span><span> </span><span id="local-6989586621680960338"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960338"><span class="hs-identifier hs-var">bs</span></a></span></span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><span class="hs-identifier">_</span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc -&gt; [Var]
forall a. HasCallStack =&gt; String -&gt; SDoc -&gt; a
</span><a href="GHC.Utils.Outputable.html#pprPanic"><span class="hs-identifier hs-var">pprPanic</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;setBndrsDemandInfo&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Var] -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960338"><span class="hs-identifier hs-var">bs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1087"></span><span>
</span><span id="line-1088"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#annotateBndr"><span class="hs-identifier hs-type">annotateBndr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1089"></span><span class="hs-comment">-- The returned env has the var deleted</span><span>
</span><span id="line-1090"></span><span class="hs-comment">-- The returned var is annotated with demand info</span><span>
</span><span id="line-1091"></span><span class="hs-comment">-- according to the result demand of the provided demand type</span><span>
</span><span id="line-1092"></span><span class="hs-comment">-- No effect on the argument demands</span><span>
</span><span id="line-1093"></span><span id="annotateBndr"><span class="annot"><span class="annottext">annotateBndr :: AnalEnv -&gt; DmdType -&gt; Var -&gt; (DmdType, Var)
</span><a href="GHC.Core.Opt.DmdAnal.html#annotateBndr"><span class="hs-identifier hs-var hs-var">annotateBndr</span></a></span></span><span> </span><span id="local-6989586621680960336"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960336"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960335"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960335"><span class="hs-identifier hs-var">dmd_ty</span></a></span></span><span> </span><span id="local-6989586621680960334"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960334"><span class="hs-identifier hs-var">var</span></a></span></span><span>
</span><span id="line-1094"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Types.Var.html#isId"><span class="hs-identifier hs-var">isId</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960334"><span class="hs-identifier hs-var">var</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960332"><span class="hs-identifier hs-var">dmd_ty'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Demand -&gt; Var
</span><a href="GHC.Types.Id.html#setIdDemandInfo"><span class="hs-identifier hs-var">setIdDemandInfo</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960334"><span class="hs-identifier hs-var">var</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960331"><span class="hs-identifier hs-var">dmd</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1095"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960335"><span class="hs-identifier hs-var">dmd_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960334"><span class="hs-identifier hs-var">var</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1096"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1097"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680960332"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960332"><span class="hs-identifier hs-var">dmd_ty'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960331"><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960331"><span class="hs-identifier hs-var">dmd</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; Bool -&gt; DmdType -&gt; Var -&gt; (DmdType, Demand)
</span><a href="GHC.Core.Opt.DmdAnal.html#findBndrDmd"><span class="hs-identifier hs-var">findBndrDmd</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960336"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960335"><span class="hs-identifier hs-var">dmd_ty</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960334"><span class="hs-identifier hs-var">var</span></a></span><span>
</span><span id="line-1098"></span><span>
</span><span id="line-1099"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#annotateLamIdBndr"><span class="hs-identifier hs-type">annotateLamIdBndr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span>
</span><span id="line-1100"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#DFunFlag"><span class="hs-identifier hs-type">DFunFlag</span></a></span><span>   </span><span class="hs-comment">-- is this lambda at the top of the RHS of a dfun?</span><span>
</span><span id="line-1101"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span>    </span><span class="hs-comment">-- Demand type of body</span><span>
</span><span id="line-1102"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span>         </span><span class="hs-comment">-- Lambda binder</span><span>
</span><span id="line-1103"></span><span>                  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span class="hs-special">,</span><span>  </span><span class="hs-comment">-- Demand type of lambda</span><span>
</span><span id="line-1104"></span><span>                      </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">)</span><span>       </span><span class="hs-comment">-- and binder annotated with demand</span><span>
</span><span id="line-1105"></span><span>
</span><span id="line-1106"></span><span id="annotateLamIdBndr"><span class="annot"><span class="annottext">annotateLamIdBndr :: AnalEnv -&gt; Bool -&gt; DmdType -&gt; Var -&gt; (DmdType, Var)
</span><a href="GHC.Core.Opt.DmdAnal.html#annotateLamIdBndr"><span class="hs-identifier hs-var hs-var">annotateLamIdBndr</span></a></span></span><span> </span><span id="local-6989586621680960329"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960329"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960328"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680960328"><span class="hs-identifier hs-var">arg_of_dfun</span></a></span></span><span> </span><span id="local-6989586621680960327"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960327"><span class="hs-identifier hs-var">dmd_ty</span></a></span></span><span> </span><span id="local-6989586621680960326"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960326"><span class="hs-identifier hs-var">id</span></a></span></span><span>
</span><span id="line-1107"></span><span class="hs-comment">-- For lambdas we add the demand to the argument demands</span><span>
</span><span id="line-1108"></span><span class="hs-comment">-- Only called for Ids</span><span>
</span><span id="line-1109"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">isId</span><span> </span><span class="hs-identifier">id</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-1110"></span><span>    </span><span class="hs-comment">-- pprTrace &quot;annLamBndr&quot; (vcat [ppr id, ppr _dmd_ty]) $</span><span>
</span><span id="line-1111"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960325"><span class="hs-identifier hs-var">final_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Demand -&gt; Var
</span><a href="GHC.Types.Id.html#setIdDemandInfo"><span class="hs-identifier hs-var">setIdDemandInfo</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960326"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960324"><span class="hs-identifier hs-var">dmd</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1112"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1113"></span><span>      </span><span class="hs-comment">-- Watch out!  See note [Lambda-bound unfoldings]</span><span>
</span><span id="line-1114"></span><span>    </span><span id="local-6989586621680960325"><span class="annot"><span class="annottext">final_ty :: DmdType
</span><a href="#local-6989586621680960325"><span class="hs-identifier hs-var hs-var">final_ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Unfolding -&gt; Maybe CoreExpr
</span><a href="GHC.Core.html#maybeUnfoldingTemplate"><span class="hs-identifier hs-var">maybeUnfoldingTemplate</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; Unfolding
</span><a href="GHC.Types.Id.html#idUnfolding"><span class="hs-identifier hs-var">idUnfolding</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960326"><span class="hs-identifier hs-var">id</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1115"></span><span>                 </span><span class="annot"><span class="annottext">Maybe CoreExpr
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960322"><span class="hs-identifier hs-var">main_ty</span></a></span><span>
</span><span id="line-1116"></span><span>                 </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680960321"><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960321"><span class="hs-identifier hs-var">unf</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960322"><span class="hs-identifier hs-var">main_ty</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; BothDmdArg -&gt; DmdType
</span><a href="GHC.Types.Demand.html#bothDmdType"><span class="hs-operator hs-var">`bothDmdType`</span></a></span><span> </span><span class="annot"><span class="annottext">BothDmdArg
</span><a href="#local-6989586621680960320"><span class="hs-identifier hs-var">unf_ty</span></a></span><span>
</span><span id="line-1117"></span><span>                          </span><span class="hs-keyword">where</span><span>
</span><span id="line-1118"></span><span>                             </span><span class="hs-special">(</span><span id="local-6989586621680960320"><span class="annot"><span class="annottext">BothDmdArg
</span><a href="#local-6989586621680960320"><span class="hs-identifier hs-var">unf_ty</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; Demand -&gt; CoreExpr -&gt; (BothDmdArg, CoreExpr)
</span><a href="GHC.Core.Opt.DmdAnal.html#dmdAnalStar"><span class="hs-identifier hs-var">dmdAnalStar</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960329"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960324"><span class="hs-identifier hs-var">dmd</span></a></span><span> </span><span class="annot"><span class="annottext">CoreExpr
</span><a href="#local-6989586621680960321"><span class="hs-identifier hs-var">unf</span></a></span><span>
</span><span id="line-1119"></span><span>
</span><span id="line-1120"></span><span>    </span><span id="local-6989586621680960322"><span class="annot"><span class="annottext">main_ty :: DmdType
</span><a href="#local-6989586621680960322"><span class="hs-identifier hs-var hs-var">main_ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Demand -&gt; DmdType -&gt; DmdType
</span><a href="GHC.Types.Demand.html#addDemand"><span class="hs-identifier hs-var">addDemand</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960324"><span class="hs-identifier hs-var">dmd</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960318"><span class="hs-identifier hs-var">dmd_ty'</span></a></span><span>
</span><span id="line-1121"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680960318"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960318"><span class="hs-identifier hs-var">dmd_ty'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960324"><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960324"><span class="hs-identifier hs-var">dmd</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; Bool -&gt; DmdType -&gt; Var -&gt; (DmdType, Demand)
</span><a href="GHC.Core.Opt.DmdAnal.html#findBndrDmd"><span class="hs-identifier hs-var">findBndrDmd</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960329"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680960328"><span class="hs-identifier hs-var">arg_of_dfun</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960327"><span class="hs-identifier hs-var">dmd_ty</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960326"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-1122"></span><span>
</span><span id="line-1123"></span><span class="hs-comment">{- Note [NOINLINE and strictness]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
At one point we disabled strictness for NOINLINE functions, on the
grounds that they should be entirely opaque.  But that lost lots of
useful semantic strictness information, so now we analyse them like
any other function, and pin strictness information on them.

That in turn forces us to worker/wrapper them; see
Note [Worker-wrapper for NOINLINE functions] in GHC.Core.Opt.WorkWrap.


Note [Lazy and unleashable free variables]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We put the strict and once-used FVs in the DmdType of the Id, so
that at its call sites we unleash demands on its strict fvs.
An example is 'roll' in imaginary/wheel-sieve2
Something like this:
        roll x = letrec
                     go y = if ... then roll (x-1) else x+1
                 in
                 go ms
We want to see that roll is strict in x, which is because
go is called.   So we put the DmdEnv for x in go's DmdType.

Another example:

        f :: Int -&gt; Int -&gt; Int
        f x y = let t = x+1
            h z = if z==0 then t else
                  if z==1 then x+1 else
                  x + h (z-1)
        in h y

Calling h does indeed evaluate x, but we can only see
that if we unleash a demand on x at the call site for t.

Incidentally, here's a place where lambda-lifting h would
lose the cigar --- we couldn't see the joint strictness in t/x

        ON THE OTHER HAND

We don't want to put *all* the fv's from the RHS into the
DmdType. Because

 * it makes the strictness signatures larger, and hence slows down fixpointing

and

 * it is useless information at the call site anyways:
   For lazy, used-many times fv's we will never get any better result than
   that, no matter how good the actual demand on the function at the call site
   is (unless it is always absent, but then the whole binder is useless).

Therefore we exclude lazy multiple-used fv's from the environment in the
DmdType.

But now the signature lies! (Missing variables are assumed to be absent.) To
make up for this, the code that analyses the binding keeps the demand on those
variable separate (usually called &quot;lazy_fv&quot;) and adds it to the demand of the
whole binding later.

What if we decide _not_ to store a strictness signature for a binding at all, as
we do when aborting a fixed-point iteration? The we risk losing the information
that the strict variables are being used. In that case, we take all free variables
mentioned in the (unsound) strictness signature, conservatively approximate the
demand put on them (topDmd), and add that to the &quot;lazy_fv&quot; returned by &quot;dmdFix&quot;.


Note [Lambda-bound unfoldings]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We allow a lambda-bound variable to carry an unfolding, a facility that is used
exclusively for join points; see Note [Case binders and join points].  If so,
we must be careful to demand-analyse the RHS of the unfolding!  Example
   \x. \y{=Just x}. &lt;body&gt;
Then if &lt;body&gt; uses 'y', then transitively it uses 'x', and we must not
forget that fact, otherwise we might make 'x' absent when it isn't.


************************************************************************
*                                                                      *
\subsection{Strictness signatures}
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-1207"></span><span>
</span><span id="line-1208"></span><span class="hs-keyword">type</span><span> </span><span id="DFunFlag"><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#DFunFlag"><span class="hs-identifier hs-var">DFunFlag</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>  </span><span class="hs-comment">-- indicates if the lambda being considered is in the</span><span>
</span><span id="line-1209"></span><span>                      </span><span class="hs-comment">-- sequence of lambdas at the top of the RHS of a dfun</span><span>
</span><span id="line-1210"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#notArgOfDfun"><span class="hs-identifier hs-type">notArgOfDfun</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#DFunFlag"><span class="hs-identifier hs-type">DFunFlag</span></a></span><span>
</span><span id="line-1211"></span><span id="notArgOfDfun"><span class="annot"><span class="annottext">notArgOfDfun :: Bool
</span><a href="GHC.Core.Opt.DmdAnal.html#notArgOfDfun"><span class="hs-identifier hs-var hs-var">notArgOfDfun</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-1212"></span><span>
</span><span id="line-1213"></span><span class="hs-comment">{-  Note [dmdAnalEnv performance]
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It's tempting to think that removing the dynflags from AnalEnv would improve
performance. After all when analysing recursive groups we end up allocating
a lot of environments. However this is not the case.

We do get some performance by making AnalEnv smaller. However very often we
defer computation which means we have to capture the dynflags in the thunks
we allocate. Doing this naively in practice causes more allocation than the
removal of DynFlags saves us.

In theory it should be possible to make this better if we are stricter in
the analysis and therefore allocate fewer thunks. But I couldn't get there
in a few hours and overall the impact on GHC here is small, and there are
bigger fish to fry. So for new the env will keep a reference to the flags.
-}</span><span>
</span><span id="line-1230"></span><span>
</span><span id="line-1231"></span><span class="hs-keyword">data</span><span> </span><span id="AnalEnv"><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-var">AnalEnv</span></a></span></span><span>
</span><span id="line-1232"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="AE"><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AE"><span class="hs-identifier hs-var">AE</span></a></span></span><span> </span><span class="hs-special">{</span><span> </span><span id="ae_dflags"><span class="annot"><span class="annottext">AnalEnv -&gt; DynFlags
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_dflags"><span class="hs-identifier hs-var hs-var">ae_dflags</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-comment">-- See Note [dmdAnalEnv performance]</span><span>
</span><span id="line-1233"></span><span>       </span><span class="hs-special">,</span><span> </span><span id="ae_sigs"><span class="annot"><span class="annottext">AnalEnv -&gt; SigEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_sigs"><span class="hs-identifier hs-var hs-var">ae_sigs</span></a></span></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#SigEnv"><span class="hs-identifier hs-type">SigEnv</span></a></span><span>
</span><span id="line-1234"></span><span>       </span><span class="hs-special">,</span><span> </span><span id="ae_virgin"><span class="annot"><span class="annottext">AnalEnv -&gt; Bool
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_virgin"><span class="hs-identifier hs-var hs-var">ae_virgin</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>    </span><span class="hs-comment">-- True on first iteration only</span><span>
</span><span id="line-1235"></span><span>                              </span><span class="hs-comment">-- See Note [Initialising strictness]</span><span>
</span><span id="line-1236"></span><span>       </span><span class="hs-special">,</span><span> </span><span id="ae_fam_envs"><span class="annot"><span class="annottext">AnalEnv -&gt; FamInstEnvs
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_fam_envs"><span class="hs-identifier hs-var hs-var">ae_fam_envs</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier hs-type">FamInstEnvs</span></a></span><span>
</span><span id="line-1237"></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1238"></span><span>
</span><span id="line-1239"></span><span>        </span><span class="hs-comment">-- We use the se_env to tell us whether to</span><span>
</span><span id="line-1240"></span><span>        </span><span class="hs-comment">-- record info about a variable in the DmdEnv</span><span>
</span><span id="line-1241"></span><span>        </span><span class="hs-comment">-- We do so if it's a LocalId, but not top-level</span><span>
</span><span id="line-1242"></span><span>        </span><span class="hs-comment">--</span><span>
</span><span id="line-1243"></span><span>        </span><span class="hs-comment">-- The DmdEnv gives the demand on the free vars of the function</span><span>
</span><span id="line-1244"></span><span>        </span><span class="hs-comment">-- when it is given enough args to satisfy the strictness signature</span><span>
</span><span id="line-1245"></span><span>
</span><span id="line-1246"></span><span class="hs-keyword">type</span><span> </span><span id="SigEnv"><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#SigEnv"><span class="hs-identifier hs-var">SigEnv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Types.Var.Env.html#VarEnv"><span class="hs-identifier hs-type">VarEnv</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Demand.html#StrictSig"><span class="hs-identifier hs-type">StrictSig</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#TopLevelFlag"><span class="hs-identifier hs-type">TopLevelFlag</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1247"></span><span>
</span><span id="line-1248"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621680960313"><span class="annot"><a href="GHC.Utils.Outputable.html#Outputable"><span class="hs-identifier hs-type">Outputable</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-1249"></span><span>  </span><span id="local-6989586621680960301"><span class="annot"><span class="annottext">ppr :: AnalEnv -&gt; SDoc
</span><a href="#local-6989586621680960301"><span class="hs-identifier hs-var hs-var hs-var hs-var">ppr</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AE"><span class="hs-identifier hs-type">AE</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ae_sigs :: AnalEnv -&gt; SigEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_sigs"><span class="hs-identifier hs-var">ae_sigs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680960300"><span class="annot"><span class="annottext">SigEnv
</span><a href="#local-6989586621680960300"><span class="hs-identifier hs-var">env</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ae_virgin :: AnalEnv -&gt; Bool
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_virgin"><span class="hs-identifier hs-var">ae_virgin</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680960299"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680960299"><span class="hs-identifier hs-var">virgin</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-1250"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;AE&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#braces"><span class="hs-identifier hs-var">braces</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span>
</span><span id="line-1251"></span><span>         </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;ae_virgin =&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680960299"><span class="hs-identifier hs-var">virgin</span></a></span><span>
</span><span id="line-1252"></span><span>         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;ae_sigs =&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">SigEnv -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">SigEnv
</span><a href="#local-6989586621680960300"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-1253"></span><span>
</span><span id="line-1254"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#emptyAnalEnv"><span class="hs-identifier hs-type">emptyAnalEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Driver.Session.html#DynFlags"><span class="hs-identifier hs-type">DynFlags</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.FamInstEnv.html#FamInstEnvs"><span class="hs-identifier hs-type">FamInstEnvs</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span>
</span><span id="line-1255"></span><span id="emptyAnalEnv"><span class="annot"><span class="annottext">emptyAnalEnv :: DynFlags -&gt; FamInstEnvs -&gt; AnalEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#emptyAnalEnv"><span class="hs-identifier hs-var hs-var">emptyAnalEnv</span></a></span></span><span> </span><span id="local-6989586621680960294"><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680960294"><span class="hs-identifier hs-var">dflags</span></a></span></span><span> </span><span id="local-6989586621680960293"><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680960293"><span class="hs-identifier hs-var">fam_envs</span></a></span></span><span>
</span><span id="line-1256"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AE :: DynFlags -&gt; SigEnv -&gt; Bool -&gt; FamInstEnvs -&gt; AnalEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#AE"><span class="hs-identifier hs-type">AE</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ae_dflags :: DynFlags
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_dflags"><span class="hs-identifier hs-var">ae_dflags</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DynFlags
</span><a href="#local-6989586621680960294"><span class="hs-identifier hs-var">dflags</span></a></span><span>
</span><span id="line-1257"></span><span>         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ae_sigs :: SigEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_sigs"><span class="hs-identifier hs-var">ae_sigs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SigEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#emptySigEnv"><span class="hs-identifier hs-var">emptySigEnv</span></a></span><span>
</span><span id="line-1258"></span><span>         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ae_virgin :: Bool
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_virgin"><span class="hs-identifier hs-var">ae_virgin</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-1259"></span><span>         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ae_fam_envs :: FamInstEnvs
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_fam_envs"><span class="hs-identifier hs-var">ae_fam_envs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680960293"><span class="hs-identifier hs-var">fam_envs</span></a></span><span>
</span><span id="line-1260"></span><span>         </span><span class="hs-special">}</span><span>
</span><span id="line-1261"></span><span>
</span><span id="line-1262"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#emptySigEnv"><span class="hs-identifier hs-type">emptySigEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#SigEnv"><span class="hs-identifier hs-type">SigEnv</span></a></span><span>
</span><span id="line-1263"></span><span id="emptySigEnv"><span class="annot"><span class="annottext">emptySigEnv :: SigEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#emptySigEnv"><span class="hs-identifier hs-var hs-var">emptySigEnv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SigEnv
forall a. VarEnv a
</span><a href="GHC.Types.Var.Env.html#emptyVarEnv"><span class="hs-identifier hs-var">emptyVarEnv</span></a></span><span>
</span><span id="line-1264"></span><span>
</span><span id="line-1265"></span><span class="hs-comment">-- | Extend an environment with the strictness IDs attached to the id</span><span>
</span><span id="line-1266"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#extendAnalEnvs"><span class="hs-identifier hs-type">extendAnalEnvs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#TopLevelFlag"><span class="hs-identifier hs-type">TopLevelFlag</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span>
</span><span id="line-1267"></span><span id="extendAnalEnvs"><span class="annot"><span class="annottext">extendAnalEnvs :: TopLevelFlag -&gt; AnalEnv -&gt; [Var] -&gt; AnalEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#extendAnalEnvs"><span class="hs-identifier hs-var hs-var">extendAnalEnvs</span></a></span></span><span> </span><span id="local-6989586621680960290"><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680960290"><span class="hs-identifier hs-var">top_lvl</span></a></span></span><span> </span><span id="local-6989586621680960289"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960289"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960288"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960288"><span class="hs-identifier hs-var">vars</span></a></span></span><span>
</span><span id="line-1268"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960289"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ae_sigs :: SigEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_sigs"><span class="hs-identifier hs-var">ae_sigs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TopLevelFlag -&gt; SigEnv -&gt; [Var] -&gt; SigEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#extendSigEnvs"><span class="hs-identifier hs-var">extendSigEnvs</span></a></span><span> </span><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680960290"><span class="hs-identifier hs-var">top_lvl</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">AnalEnv -&gt; SigEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_sigs"><span class="hs-identifier hs-var hs-var">ae_sigs</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960289"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960288"><span class="hs-identifier hs-var">vars</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1269"></span><span>
</span><span id="line-1270"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#extendSigEnvs"><span class="hs-identifier hs-type">extendSigEnvs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#TopLevelFlag"><span class="hs-identifier hs-type">TopLevelFlag</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#SigEnv"><span class="hs-identifier hs-type">SigEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#SigEnv"><span class="hs-identifier hs-type">SigEnv</span></a></span><span>
</span><span id="line-1271"></span><span id="extendSigEnvs"><span class="annot"><span class="annottext">extendSigEnvs :: TopLevelFlag -&gt; SigEnv -&gt; [Var] -&gt; SigEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#extendSigEnvs"><span class="hs-identifier hs-var hs-var">extendSigEnvs</span></a></span></span><span> </span><span id="local-6989586621680960286"><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680960286"><span class="hs-identifier hs-var">top_lvl</span></a></span></span><span> </span><span id="local-6989586621680960285"><span class="annot"><span class="annottext">SigEnv
</span><a href="#local-6989586621680960285"><span class="hs-identifier hs-var">sigs</span></a></span></span><span> </span><span id="local-6989586621680960284"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960284"><span class="hs-identifier hs-var">vars</span></a></span></span><span>
</span><span id="line-1272"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SigEnv -&gt; [(Var, (StrictSig, TopLevelFlag))] -&gt; SigEnv
forall a. VarEnv a -&gt; [(Var, a)] -&gt; VarEnv a
</span><a href="GHC.Types.Var.Env.html#extendVarEnvList"><span class="hs-identifier hs-var">extendVarEnvList</span></a></span><span> </span><span class="annot"><span class="annottext">SigEnv
</span><a href="#local-6989586621680960285"><span class="hs-identifier hs-var">sigs</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960282"><span class="hs-identifier hs-var">var</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Var -&gt; StrictSig
</span><a href="GHC.Types.Id.html#idStrictness"><span class="hs-identifier hs-var">idStrictness</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960282"><span class="hs-identifier hs-var">var</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680960286"><span class="hs-identifier hs-var">top_lvl</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621680960282"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960282"><span class="hs-identifier hs-var">var</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960284"><span class="hs-identifier hs-var">vars</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-1273"></span><span>
</span><span id="line-1274"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#extendAnalEnv"><span class="hs-identifier hs-type">extendAnalEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#TopLevelFlag"><span class="hs-identifier hs-type">TopLevelFlag</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#StrictSig"><span class="hs-identifier hs-type">StrictSig</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span>
</span><span id="line-1275"></span><span id="extendAnalEnv"><span class="annot"><span class="annottext">extendAnalEnv :: TopLevelFlag -&gt; AnalEnv -&gt; Var -&gt; StrictSig -&gt; AnalEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#extendAnalEnv"><span class="hs-identifier hs-var hs-var">extendAnalEnv</span></a></span></span><span> </span><span id="local-6989586621680960281"><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680960281"><span class="hs-identifier hs-var">top_lvl</span></a></span></span><span> </span><span id="local-6989586621680960280"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960280"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960279"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960279"><span class="hs-identifier hs-var">var</span></a></span></span><span> </span><span id="local-6989586621680960278"><span class="annot"><span class="annottext">StrictSig
</span><a href="#local-6989586621680960278"><span class="hs-identifier hs-var">sig</span></a></span></span><span>
</span><span id="line-1276"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960280"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ae_sigs :: SigEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_sigs"><span class="hs-identifier hs-var">ae_sigs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TopLevelFlag -&gt; SigEnv -&gt; Var -&gt; StrictSig -&gt; SigEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#extendSigEnv"><span class="hs-identifier hs-var">extendSigEnv</span></a></span><span> </span><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680960281"><span class="hs-identifier hs-var">top_lvl</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">AnalEnv -&gt; SigEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_sigs"><span class="hs-identifier hs-var hs-var">ae_sigs</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960280"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960279"><span class="hs-identifier hs-var">var</span></a></span><span> </span><span class="annot"><span class="annottext">StrictSig
</span><a href="#local-6989586621680960278"><span class="hs-identifier hs-var">sig</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1277"></span><span>
</span><span id="line-1278"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#extendSigEnv"><span class="hs-identifier hs-type">extendSigEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#TopLevelFlag"><span class="hs-identifier hs-type">TopLevelFlag</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#SigEnv"><span class="hs-identifier hs-type">SigEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#StrictSig"><span class="hs-identifier hs-type">StrictSig</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#SigEnv"><span class="hs-identifier hs-type">SigEnv</span></a></span><span>
</span><span id="line-1279"></span><span id="extendSigEnv"><span class="annot"><span class="annottext">extendSigEnv :: TopLevelFlag -&gt; SigEnv -&gt; Var -&gt; StrictSig -&gt; SigEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#extendSigEnv"><span class="hs-identifier hs-var hs-var">extendSigEnv</span></a></span></span><span> </span><span id="local-6989586621680960276"><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680960276"><span class="hs-identifier hs-var">top_lvl</span></a></span></span><span> </span><span id="local-6989586621680960275"><span class="annot"><span class="annottext">SigEnv
</span><a href="#local-6989586621680960275"><span class="hs-identifier hs-var">sigs</span></a></span></span><span> </span><span id="local-6989586621680960274"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960274"><span class="hs-identifier hs-var">var</span></a></span></span><span> </span><span id="local-6989586621680960273"><span class="annot"><span class="annottext">StrictSig
</span><a href="#local-6989586621680960273"><span class="hs-identifier hs-var">sig</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SigEnv -&gt; Var -&gt; (StrictSig, TopLevelFlag) -&gt; SigEnv
forall a. VarEnv a -&gt; Var -&gt; a -&gt; VarEnv a
</span><a href="GHC.Types.Var.Env.html#extendVarEnv"><span class="hs-identifier hs-var">extendVarEnv</span></a></span><span> </span><span class="annot"><span class="annottext">SigEnv
</span><a href="#local-6989586621680960275"><span class="hs-identifier hs-var">sigs</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960274"><span class="hs-identifier hs-var">var</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">StrictSig
</span><a href="#local-6989586621680960273"><span class="hs-identifier hs-var">sig</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TopLevelFlag
</span><a href="#local-6989586621680960276"><span class="hs-identifier hs-var">top_lvl</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1280"></span><span>
</span><span id="line-1281"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#lookupSigEnv"><span class="hs-identifier hs-type">lookupSigEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Demand.html#StrictSig"><span class="hs-identifier hs-type">StrictSig</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#TopLevelFlag"><span class="hs-identifier hs-type">TopLevelFlag</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1282"></span><span id="lookupSigEnv"><span class="annot"><span class="annottext">lookupSigEnv :: AnalEnv -&gt; Var -&gt; Maybe (StrictSig, TopLevelFlag)
</span><a href="GHC.Core.Opt.DmdAnal.html#lookupSigEnv"><span class="hs-identifier hs-var hs-var">lookupSigEnv</span></a></span></span><span> </span><span id="local-6989586621680960271"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960271"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960270"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960270"><span class="hs-identifier hs-var">id</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SigEnv -&gt; Var -&gt; Maybe (StrictSig, TopLevelFlag)
forall a. VarEnv a -&gt; Var -&gt; Maybe a
</span><a href="GHC.Types.Var.Env.html#lookupVarEnv"><span class="hs-identifier hs-var">lookupVarEnv</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">AnalEnv -&gt; SigEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_sigs"><span class="hs-identifier hs-var hs-var">ae_sigs</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960271"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960270"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-1283"></span><span>
</span><span id="line-1284"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#nonVirgin"><span class="hs-identifier hs-type">nonVirgin</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span>
</span><span id="line-1285"></span><span id="nonVirgin"><span class="annot"><span class="annottext">nonVirgin :: AnalEnv -&gt; AnalEnv
</span><a href="GHC.Core.Opt.DmdAnal.html#nonVirgin"><span class="hs-identifier hs-var hs-var">nonVirgin</span></a></span></span><span> </span><span id="local-6989586621680960268"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960268"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960268"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ae_virgin :: Bool
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_virgin"><span class="hs-identifier hs-var">ae_virgin</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1286"></span><span>
</span><span id="line-1287"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#findBndrsDmds"><span class="hs-identifier hs-type">findBndrsDmds</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#Var"><span class="hs-identifier hs-type">Var</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Demand.html#Demand"><span class="hs-identifier hs-type">Demand</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-1288"></span><span class="hs-comment">-- Return the demands on the Ids in the [Var]</span><span>
</span><span id="line-1289"></span><span id="findBndrsDmds"><span class="annot"><span class="annottext">findBndrsDmds :: AnalEnv -&gt; DmdType -&gt; [Var] -&gt; (DmdType, [Demand])
</span><a href="GHC.Core.Opt.DmdAnal.html#findBndrsDmds"><span class="hs-identifier hs-var hs-var">findBndrsDmds</span></a></span></span><span> </span><span id="local-6989586621680960267"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960267"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960266"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960266"><span class="hs-identifier hs-var">dmd_ty</span></a></span></span><span> </span><span id="local-6989586621680960265"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960265"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span>
</span><span id="line-1290"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; [Var] -&gt; (DmdType, [Demand])
</span><a href="#local-6989586621680960264"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960266"><span class="hs-identifier hs-var">dmd_ty</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960265"><span class="hs-identifier hs-var">bndrs</span></a></span><span>
</span><span id="line-1291"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1292"></span><span>    </span><span id="local-6989586621680960264"><span class="annot"><span class="annottext">go :: DmdType -&gt; [Var] -&gt; (DmdType, [Demand])
</span><a href="#local-6989586621680960264"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span id="local-6989586621680960263"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960263"><span class="hs-identifier hs-var">dmd_ty</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960263"><span class="hs-identifier hs-var">dmd_ty</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-1293"></span><span>    </span><span class="annot"><a href="#local-6989586621680960264"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621680960262"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960262"><span class="hs-identifier hs-var">dmd_ty</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680960261"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960261"><span class="hs-identifier hs-var">b</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680960260"><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960260"><span class="hs-identifier hs-var">bs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-1294"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Bool
</span><a href="GHC.Types.Var.html#isId"><span class="hs-identifier hs-var">isId</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960261"><span class="hs-identifier hs-var">b</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680960259"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960259"><span class="hs-identifier hs-var">dmd_ty1</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960258"><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960258"><span class="hs-identifier hs-var">dmds</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; [Var] -&gt; (DmdType, [Demand])
</span><a href="#local-6989586621680960264"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960262"><span class="hs-identifier hs-var">dmd_ty</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960260"><span class="hs-identifier hs-var">bs</span></a></span><span>
</span><span id="line-1295"></span><span>                        </span><span class="hs-special">(</span><span id="local-6989586621680960257"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960257"><span class="hs-identifier hs-var">dmd_ty2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960256"><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960256"><span class="hs-identifier hs-var">dmd</span></a></span></span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; Bool -&gt; DmdType -&gt; Var -&gt; (DmdType, Demand)
</span><a href="GHC.Core.Opt.DmdAnal.html#findBndrDmd"><span class="hs-identifier hs-var">findBndrDmd</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960267"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960259"><span class="hs-identifier hs-var">dmd_ty1</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960261"><span class="hs-identifier hs-var">b</span></a></span><span>
</span><span id="line-1296"></span><span>                    </span><span class="hs-keyword">in</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960257"><span class="hs-identifier hs-var">dmd_ty2</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960256"><span class="hs-identifier hs-var">dmd</span></a></span><span> </span><span class="annot"><span class="annottext">Demand -&gt; [Demand] -&gt; [Demand]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[Demand]
</span><a href="#local-6989586621680960258"><span class="hs-identifier hs-var">dmds</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1297"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; [Var] -&gt; (DmdType, [Demand])
</span><a href="#local-6989586621680960264"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960262"><span class="hs-identifier hs-var">dmd_ty</span></a></span><span> </span><span class="annot"><span class="annottext">[Var]
</span><a href="#local-6989586621680960260"><span class="hs-identifier hs-var">bs</span></a></span><span>
</span><span id="line-1298"></span><span>
</span><span id="line-1299"></span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#findBndrDmd"><span class="hs-identifier hs-type">findBndrDmd</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Opt.DmdAnal.html#AnalEnv"><span class="hs-identifier hs-type">AnalEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Demand.html#DmdType"><span class="hs-identifier hs-type">DmdType</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.Demand.html#Demand"><span class="hs-identifier hs-type">Demand</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1300"></span><span class="hs-comment">-- See Note [Trimming a demand to a type]</span><span>
</span><span id="line-1301"></span><span id="findBndrDmd"><span class="annot"><span class="annottext">findBndrDmd :: AnalEnv -&gt; Bool -&gt; DmdType -&gt; Var -&gt; (DmdType, Demand)
</span><a href="GHC.Core.Opt.DmdAnal.html#findBndrDmd"><span class="hs-identifier hs-var hs-var">findBndrDmd</span></a></span></span><span> </span><span id="local-6989586621680960255"><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960255"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span id="local-6989586621680960254"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680960254"><span class="hs-identifier hs-var">arg_of_dfun</span></a></span></span><span> </span><span id="local-6989586621680960253"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960253"><span class="hs-identifier hs-var">dmd_ty</span></a></span></span><span> </span><span id="local-6989586621680960252"><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960252"><span class="hs-identifier hs-var">id</span></a></span></span><span>
</span><span id="line-1302"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960251"><span class="hs-identifier hs-var">dmd_ty'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960250"><span class="hs-identifier hs-var">dmd'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1303"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-1304"></span><span>    </span><span id="local-6989586621680960250"><span class="annot"><span class="annottext">dmd' :: Demand
</span><a href="#local-6989586621680960250"><span class="hs-identifier hs-var hs-var">dmd'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Demand -&gt; Demand
</span><a href="#local-6989586621680960249"><span class="hs-identifier hs-var">strictify</span></a></span><span> </span><span class="annot"><span class="annottext">(Demand -&gt; Demand) -&gt; Demand -&gt; Demand
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-1305"></span><span>           </span><span class="annot"><span class="annottext">Demand -&gt; TypeShape -&gt; Demand
</span><a href="GHC.Types.Demand.html#trimToType"><span class="hs-identifier hs-var">trimToType</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960247"><span class="hs-identifier hs-var">starting_dmd</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FamInstEnvs -&gt; Type -&gt; TypeShape
</span><a href="GHC.Core.Opt.WorkWrap.Utils.html#findTypeShape"><span class="hs-identifier hs-var">findTypeShape</span></a></span><span> </span><span class="annot"><span class="annottext">FamInstEnvs
</span><a href="#local-6989586621680960245"><span class="hs-identifier hs-var">fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680960244"><span class="hs-identifier hs-var">id_ty</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1306"></span><span>
</span><span id="line-1307"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680960251"><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960251"><span class="hs-identifier hs-var">dmd_ty'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680960247"><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960247"><span class="hs-identifier hs-var">starting_dmd</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DmdType -&gt; Var -&gt; (DmdType, Demand)
</span><a href="GHC.Types.Demand.html#peelFV"><span class="hs-identifier hs-var">peelFV</span></a></span><span> </span><span class="annot"><span class="annottext">DmdType
</span><a href="#local-6989586621680960253"><span class="hs-identifier hs-var">dmd_ty</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960252"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-1308"></span><span>
</span><span id="line-1309"></span><span>    </span><span id="local-6989586621680960244"><span class="annot"><span class="annottext">id_ty :: Type
</span><a href="#local-6989586621680960244"><span class="hs-identifier hs-var hs-var">id_ty</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Var -&gt; Type
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">Var
</span><a href="#local-6989586621680960252"><span class="hs-identifier hs-var">id</span></a></span><span>
</span><span id="line-1310"></span><span>
</span><span id="line-1311"></span><span>    </span><span id="local-6989586621680960249"><span class="annot"><span class="annottext">strictify :: Demand -&gt; Demand
</span><a href="#local-6989586621680960249"><span class="hs-identifier hs-var hs-var">strictify</span></a></span></span><span> </span><span id="local-6989586621680960241"><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960241"><span class="hs-identifier hs-var">dmd</span></a></span></span><span>
</span><span id="line-1312"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">GeneralFlag -&gt; DynFlags -&gt; Bool
</span><a href="GHC.Driver.Session.html#gopt"><span class="hs-identifier hs-var">gopt</span></a></span><span> </span><span class="annot"><span class="annottext">GeneralFlag
</span><a href="GHC.Driver.Flags.html#Opt_DictsStrict"><span class="hs-identifier hs-var">Opt_DictsStrict</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">AnalEnv -&gt; DynFlags
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_dflags"><span class="hs-identifier hs-var hs-var">ae_dflags</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960255"><span class="hs-identifier hs-var">env</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1313"></span><span>             </span><span class="hs-comment">-- We never want to strictify a recursive let. At the moment</span><span>
</span><span id="line-1314"></span><span>             </span><span class="hs-comment">-- annotateBndr is only call for non-recursive lets; if that</span><span>
</span><span id="line-1315"></span><span>             </span><span class="hs-comment">-- changes, we need a RecFlag parameter and another guard here.</span><span>
</span><span id="line-1316"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680960254"><span class="hs-identifier hs-var">arg_of_dfun</span></a></span><span> </span><span class="hs-comment">-- See Note [Do not strictify the argument dictionaries of a dfun]</span><span>
</span><span id="line-1317"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Type -&gt; Demand -&gt; Demand
</span><a href="GHC.Types.Demand.html#strictifyDictDmd"><span class="hs-identifier hs-var">strictifyDictDmd</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680960244"><span class="hs-identifier hs-var">id_ty</span></a></span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960241"><span class="hs-identifier hs-var">dmd</span></a></span><span>
</span><span id="line-1318"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-1319"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Demand
</span><a href="#local-6989586621680960241"><span class="hs-identifier hs-var">dmd</span></a></span><span>
</span><span id="line-1320"></span><span>
</span><span id="line-1321"></span><span>    </span><span id="local-6989586621680960245"><span class="annot"><span class="annottext">fam_envs :: FamInstEnvs
</span><a href="#local-6989586621680960245"><span class="hs-identifier hs-var hs-var">fam_envs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">AnalEnv -&gt; FamInstEnvs
</span><a href="GHC.Core.Opt.DmdAnal.html#ae_fam_envs"><span class="hs-identifier hs-var hs-var">ae_fam_envs</span></a></span><span> </span><span class="annot"><span class="annottext">AnalEnv
</span><a href="#local-6989586621680960255"><span class="hs-identifier hs-var">env</span></a></span><span>
</span><span id="line-1322"></span><span>
</span><span id="line-1323"></span><span class="hs-comment">{- Note [Initialising strictness]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
See section 9.2 (Finding fixpoints) of the paper.

Our basic plan is to initialise the strictness of each Id in a
recursive group to &quot;bottom&quot;, and find a fixpoint from there.  However,
this group B might be inside an *enclosing* recursive group A, in
which case we'll do the entire fixpoint shebang on for each iteration
of A. This can be illustrated by the following example:

Example:

  f [] = []
  f (x:xs) = let g []     = f xs
                 g (y:ys) = y+1 : g ys
              in g (h x)

At each iteration of the fixpoint for f, the analyser has to find a
fixpoint for the enclosed function g. In the meantime, the demand
values for g at each iteration for f are *greater* than those we
encountered in the previous iteration for f. Therefore, we can begin
the fixpoint for g not with the bottom value but rather with the
result of the previous analysis. I.e., when beginning the fixpoint
process for g, we can start from the demand signature computed for g
previously and attached to the binding occurrence of g.

To speed things up, we initialise each iteration of A (the enclosing
one) from the result of the last one, which is neatly recorded in each
binder.  That way we make use of earlier iterations of the fixpoint
algorithm. (Cunning plan.)

But on the *first* iteration we want to *ignore* the current strictness
of the Id, and start from &quot;bottom&quot;.  Nowadays the Id can have a current
strictness, because interface files record strictness for nested bindings.
To know when we are in the first iteration, we look at the ae_virgin
field of the AnalEnv.


Note [Final Demand Analyser run]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Some of the information that the demand analyser determines is not always
preserved by the simplifier.  For example, the simplifier will happily rewrite
  \y [Demand=1*U] let x = y in x + x
to
  \y [Demand=1*U] y + y
which is quite a lie.

The once-used information is (currently) only used by the code
generator, though.  So:

 * We zap the used-once info in the worker-wrapper;
   see Note [Zapping Used Once info in WorkWrap] in
   GHC.Core.Opt.WorkWrap.
   If it's not reliable, it's better not to have it at all.

 * Just before TidyCore, we add a pass of the demand analyser,
      but WITHOUT subsequent worker/wrapper and simplifier,
   right before TidyCore.  See SimplCore.getCoreToDo.

   This way, correct information finds its way into the module interface
   (strictness signatures!) and the code generator (single-entry thunks!)

Note that, in contrast, the single-call information (C1(..)) /can/ be
relied upon, as the simplifier tends to be very careful about not
duplicating actual function calls.

Also see #11731.
-}</span><span>
</span><span id="line-1391"></span></pre></body></html>